home *** CD-ROM | disk | FTP | other *** search
/ Crosscountry USA Photo Safari / Crosscountry USA Photo Safari.iso / Data / cc_base / pak00_16bit_f.pk3 / dash.gl.p < prev    next >
Text File  |  2003-10-20  |  121KB  |  3,054 lines

  1. {
  2.   ActiveWhileHidden = True;
  3.   Hidden = True;
  4.   ScriptID = script {
  5.     @setup {
  6.       
  7.       /* preload pavement road */
  8.       ResByName("anim/road/pavement_ddu.anm");
  9.       ResByName("anim/road/pavement_dwu.anm");
  10.       ResByName("anim/road/pavement_dsu.anm");
  11.       ResByName("anim/road/pavement_ndu.anm");
  12.       ResByName("anim/road/pavement_nwu.anm");
  13.       ResByName("anim/road/pavement_nsu.anm");
  14.       ResByName("anim/road/pavement_ddl.anm");
  15.       ResByName("anim/road/pavement_dwl.anm");
  16.       ResByName("anim/road/pavement_dsl.anm");
  17.       ResByName("anim/road/pavement_ndl.anm");
  18.       ResByName("anim/road/pavement_nwl.anm");
  19.       ResByName("anim/road/pavement_nsl.anm");
  20.  
  21.       /* preload wipers */
  22.       ResByName("gui/dash/wipers/day/wipers.anm");
  23.       ResByName("gui/dash/wipers/night/wipers_n.anm");
  24.       
  25.       /* preload tab images */
  26.       ResByName("gui/dash/tab/eat/eat_off.pcx");
  27.       ResByName("gui/dash/tab/eat/eat_on.pcx");
  28.       ResByName("gui/dash/tab/postcard/postcard_off.pcx");
  29.       ResByName("gui/dash/tab/postcard/postcard_on.pcx");
  30.       ResByName("gui/dash/tab/load/load_off.pcx");
  31.       ResByName("gui/dash/tab/load/load_on.pcx");
  32.       ResByName("gui/dash/tab/maintenance/maintenance_on.pcx");    
  33.       ResByName("gui/dash/tab/maintenance/maintenance_off.pcx");
  34.  
  35.       /* preload images... */     
  36.       ResByName("font/clock.tf");
  37.       ResByName("font/radio.tf");
  38.       ResByName("anim/dash/day/dash_upper.pcx");
  39.       ResByName("anim/dash/day/dash_lower.bmp");
  40.       ResByName("anim/dash/night/dash_lower_n.bmp");  
  41.       ResByName("anim/dash/night/dash_upper_n.pcx");    
  42.       ResByName("gui/dash/radio/day/radio_left.pcx");              
  43.       ResByName("gui/dash/radio/day/radio_right.pcx");
  44.       ResByName("gui/dash/ignition_switch/day/ignition.anm");
  45.       ResByName("gui/dash/wiper_switch/day/wiper_on.pcx");              
  46.       ResByName("gui/dash/wiper_switch/day/wiper_off.pcx");  
  47.       ResByName("gui/dash/light_switch/day/light_switch_on.pcx");              
  48.       ResByName("gui/dash/light_switch/day/light_switch_off.pcx");             
  49.       ResByName("anim/dash/night/dash_upper_n.pcx");
  50.       ResByName("anim/dash/night/dash_lower_n.bmp");
  51.       ResByName("gui/dash/ignition_switch/night/ignition.anm");
  52.       ResByName("gui/dash/wiper_switch/night/wiper_on_n.pcx");
  53.       ResByName("gui/dash/wiper_switch/night/wiper_off_n.pcx");
  54.       ResByName("gui/dash/light_switch/night/light_switch_on_n.pcx");    
  55.       ResByName("gui/dash/light_switch/night/light_switch_off_n.pcx");  
  56.       ResByName("gui/dash/radio/night/radio_left_n.pcx");              
  57.       ResByName("gui/dash/radio/night/radio_right_n.pcx");  
  58.       ResByName("anim/dash/night/dash_lower_n.bmp");  
  59.       ResByName("anim/dash/night/dash_upper_n.pcx");  
  60.             
  61.       /* preload sounds */
  62.       ResByName("sound/buckle.wav");
  63.       ResByName("sound/unbuckle.wav");      
  64.       ResByName("sound/airbrake.wav");
  65.       ResByName("sound/toggle.wav");
  66.       ResByName("sound/idle.wav");
  67.       ResByName("sound/truck_start.wav");
  68.       ResByName("sound/truck_stop.wav");
  69.       ResByName("sound/high_idle.wav");
  70.       ResByName("sound/gear_up.wav");
  71.       ResByName("sound/very_high_idle.wav");
  72.       ResByName("sound/camera_shutter.wav");
  73.       ResByName("sound/out_of_gas.wav");
  74.  
  75.       /* DJ Claimed these were preloaded, but he lied */
  76.       ResByName("sound/wiper_dry.wav");
  77.       ResByName("sound/wiper_wet.wav");
  78.       
  79.       
  80.       /* preload music  */
  81.       ResByName("sound/radio/radio_1.wav");
  82.       ResByName("sound/radio/radio_2.wav");
  83.       ResByName("sound/radio/radio_3.wav");
  84.       ResByName("sound/radio/radio_4.wav");
  85.       ResByName("sound/radio/radio_5.wav");
  86.       ResByName("sound/radio/radio_6.wav");
  87.       ResByName("sound/radio/radio_7.wav");
  88.       ResByName("sound/radio/radio_8.wav");
  89.       ResByName("sound/radio/radio_9.wav");
  90.       ResByName("sound/radio/tuning/tuning_1.wav");
  91.       ResByName("sound/radio/tuning/tuning_2.wav");
  92.       ResByName("sound/radio/tuning/tuning_3.wav");  
  93.       ResByName("sound/radio/tuning/tuning_4.wav"); 
  94.       ResByName("sound/radio/tuning/tuning_5.wav");
  95.       ResByName("sound/radio/static/static_1.wav");
  96.       ResByName("sound/radio/static/static_2.wav");
  97.     }
  98.     @loaded {
  99.       GuiToFront(ResByName("postcard.tab"));
  100.       GuiToFront(ResByName("eat.tab"));
  101.       GuiToFront(ResByName("load.tab"));
  102.       GuiToFront(ResByName("system.tab"));
  103.       GuiToFront(ResByName("fuel.tab"));
  104.       GuiToFront(ResByName("maintenance.tab"));
  105.       GuiToFront(ResByName("sleep.tab"));
  106.       GuiToFront(ResByName("timezone.tab"));
  107.     }
  108.   }
  109.  
  110.   ChildID = {
  111.  
  112.    
  113.     GuiSegmentController("SegmentController") {
  114.  
  115.       ScriptID = script {
  116.         @loaded {
  117.           ResPropSetInt(SELF,"state",7);          
  118.         }
  119.         @animate {
  120.         
  121. /* 
  122.  segment controller states:
  123.  stopped = 0, 
  124.  running = 1, 
  125.  waiting_for_load = 2, 
  126.  starting = 3, 
  127.  pause = 4, 
  128.  paused = 5, 
  129.  unpause = 6, 
  130.  display_city_scape = 7, 
  131.  tow_truck = 8 
  132.  po po = 9, 
  133.  accident = 10, 
  134.  ferry = 11 
  135. */        
  136.         
  137.           int frame_number;
  138.           int state;              
  139.           int segment_type;       /* begin = 0, middle = 1, end = 2 */
  140.           int segment_direction;  /* forward = 1, backward = -1 */
  141.           int segment_number;     /* the row num in the csv file that we are using */
  142.           int segment_distance;   /* distance of the segment */
  143.           int repeat_number;      /* how many times the segment is looped */
  144.           int truck_trip_meter_cached; /* mileage cache */
  145.           int truck_trip_meter;        /* mileage cache */
  146.           int city_y;             /* the y position of the city */
  147.           int city_x;             /* the x position of the city */
  148.           int view_port_width;    /* the Width of our laptop tile view port */
  149.           int view_port_height;   /* the Height of our laptop tile view port */
  150.           int cur_frame;          /* the current frame we are on */
  151.           int truck_x;            /* the x position of the truck on the map */
  152.           int truck_y;            /* the y position of the truck on the map */
  153.           int xb;                 /* the beginning x position of a segment */
  154.           int yb;                 /* the beginning y position of a segment */
  155.           int xe;                 /* the ending x position of a segment */
  156.           int ye;                 /* the ending y position of a segment */
  157.           int time_now;           /* the time that the clock shows */
  158.           int time_to_add;        /* the time to add to the clock */
  159.           int truck_fuel_remaining;        /* the fuel remaining */
  160.           int city_row;                    /* the csv row number of the city we are in */
  161.           str nav_cur_city;                /* the current city we are in */
  162.           str time_of_day;                 /* d = day, n = night */
  163.           str season;                      /* s = summer, w = winter */
  164.           str weather;                     /* d = dry, w = wet, s = snow */
  165.           str precip;                      /* r = raining, s = snowing, n = none */
  166.           int game_distance_per_fuel_unit; /* miles per gallon really */
  167.           int fuel_used;                   
  168.           int player_fatigue;
  169.           int player_hunger;
  170.           str head_light_flag;
  171.           str postcard;
  172.           str sign_type;
  173.           int time_last_player_switch;
  174.           str rname;              /* a temp var to hold name of res to load */
  175.           str tmp;                /* generic tmp var to hold strings */
  176.           str tmp2;
  177.           int tmp_int;            /* generic tmp var to hold ints */
  178.           int tmp2_int;
  179.  
  180.           int expense_spent_on_mishap;
  181.           int expense_spent_on_ticket;
  182.           resid restoload;        /* a resid to use as a temp place to hold resid's */
  183.           resid csv_data_id;
  184.           resid route_data_id;        /* the route data, all segment data is in this csv file */
  185.           resid city_data_id;         /* the city data,  all city data is in this csv file */
  186.           resid adorn_data_id;
  187.           resid state_data_id;        /* the state data */
  188.           resid Message;          /* for when we print to message */
  189.           resid Player;
  190.           resid Game;
  191.           resid PlayerPhoto;      /* list of photos */
  192.  
  193.           ResPropAlias(SELF,"state", "state");
  194.  
  195.  
  196.           if (state == 2 /* waiting_for_load */) {
  197.             if (ResActive(ResPropGetResID(SELF, "load_watch_id")) ) {
  198.               /* Log(LOG_DEBUG,"\n switching state to running \n"); */
  199.               state = 1;
  200.               ResPropSetResID(SELF,"load_watch_id",RES_INVALID);
  201.               /* fall through to state 1 so we don't miss the first frame */
  202.             } else {
  203.               /* Log(LOG_DEBUG,"\n still waiting for load...\n"); */
  204.               stop;
  205.             }
  206.           }
  207.  
  208.           csv_data_id = ResByName("CSVData");
  209.           route_data_id = ResPropGetResID(csv_data_id, "route_id");
  210.           city_data_id = ResPropGetResID(csv_data_id, "city_id");  
  211.           state_data_id = ResPropGetResID(csv_data_id, "state_id");  
  212.           adorn_data_id = ResPropGetResID(csv_data_id, "adorn_id");
  213.           
  214.           
  215.           Game = ResByName("Game");   
  216.           Player = ResPropGetResID(Game,"game_cur_player");
  217.           Message = GuiSiblingByName("message");
  218.           time_now = ResPropGetInt(Player,"time_now");          
  219.           
  220.           ResPropAlias(Player, "nav_cur_city","nav_cur_city");          
  221.           ResPropAlias(SELF,   "truck_trip_meter_cached","truck_trip_meter_cached");
  222.           ResPropAlias(Player, "truck_trip_meter","truck_trip_meter");
  223.           ResPropAlias(SELF,   "segment_direction","segment_direction");
  224.           ResPropAlias(SELF,   "segment_type","segment_type");
  225.           ResPropAlias(SELF,   "frame_number","frame_number");
  226.           ResPropAlias(SELF,   "repeat_number","repeat_number");
  227.           ResPropAlias(SELF,   "segment_number","segment_number");
  228.           ResPropAlias(Player, "truck_fuel_remaining","truck_fuel_remaining");
  229.           ResPropAlias(Game,   "game_distance_per_fuel_unit","game_distance_per_fuel_unit");
  230.           ResPropAlias(Player, "player_hunger","player_hunger");
  231.           ResPropAlias(Player, "player_fatigue","player_fatigue");
  232.           ResPropAlias(Player, "nav_truck_x","truck_x");
  233.           ResPropAlias(Player, "nav_truck_y","truck_y");                   
  234.           ResPropAlias(Player, "weather_time_of_day","time_of_day");
  235.           ResPropAlias(Player, "weather_season","season");
  236.           ResPropAlias(Player, "weather_weather","weather");
  237.           ResPropAlias(Player, "weather_precip","precip");                 
  238.           ResPropAlias(Game,   "game_time_last_player_switch","time_last_player_switch");
  239.  
  240.  
  241.           /* IF THE SEGMENT IS RUNNING */
  242.           if (state == 1 /*running*/ ) {
  243.             
  244.             if ( (repeat_number == 1) && (frame_number == 0) ) {
  245.               /* calculate the chance of being pulled over */
  246.               ResParseEvent(ResByName("common/calc_cop.c4"),"@calc_cop");
  247.               if ( state == 9) {
  248.                 stop;
  249.               }
  250.                             
  251.               /* calculate the chance of accident */
  252.               ResParseEvent(ResByName("common/calc_accident.c4"),"@calc_accident"); 
  253.               if ( state == 10) {
  254.                 stop;
  255.               }
  256.  
  257.             }
  258.           
  259.           
  260.             /* Log(LOG_DEBUG,"\n increasing frame \n"); */
  261.             frame_number += 1;
  262.  
  263.             if (frame_number >= 16) {
  264.               /* Log(LOG_DEBUG,"\n setting frame to zero\n"); */
  265.               frame_number = 0;
  266.               repeat_number += 1;
  267.  
  268.               if (ResPropGetInt(SELF, "adorn1_left_play_once")) {
  269.                 ResPropSetResID(GuiSiblingByName("left_adorn1"), "AnimationID", RES_INVALID);
  270.               }
  271.               if (ResPropGetInt(SELF, "adorn1_right_play_once")) {
  272.                 ResPropSetResID(GuiSiblingByName("right_adorn1"), "AnimationID", RES_INVALID);
  273.               }
  274.             }
  275.  
  276.  
  277.  
  278.             if (repeat_number >= 2) {
  279.               repeat_number = 0;
  280.  
  281.               /* add mileage to the trip-o-meter */
  282.               segment_distance = StrToInt(CSVGetStr(route_data_id,"distance",segment_number));
  283.               truck_trip_meter_cached += segment_distance;
  284.               truck_trip_meter = truck_trip_meter_cached;
  285.               
  286.              
  287.               /* if we are at a city */
  288.               if (((segment_type == 2/*end*/)   && (segment_direction == 1/*forward*/)) ||
  289.                   ((segment_type == 0/*begin*/) && (segment_direction == -1/*backward*/))) {
  290.  
  291.                 /* Log(LOG_DEBUG,"\n switching state to stopped  - arrived at city\n"); */
  292.                
  293.                 /* send an activate event to the brake pedal */
  294.                 ResParseEvent(GuiSiblingByName("brake_pedal"),"@activate");
  295.                 
  296.                 state = 7;
  297.                 
  298.                 /* clear flickers, sky, hide road, etc... */
  299.                 /* Log(LOG_DEBUG,"\n clearing flickers, road, sky, etc. \n"); */
  300.                 ResPropSetResID(GuiSiblingByName("left_flicker") , "AnimationID", RES_INVALID);
  301.                 ResPropSetResID(GuiSiblingByName("right_flicker"), "AnimationID", RES_INVALID);
  302.                 ResPropSetResID(GuiSiblingByName("left_adorn1")  , "AnimationID", RES_INVALID);
  303.                 ResPropSetResID(GuiSiblingByName("right_adorn1") , "AnimationID", RES_INVALID);
  304.                 ResPropSetResID(GuiSiblingByName("sign")         , "AnimationID", RES_INVALID);
  305.                 ResPropSetInt(GuiSiblingByName("road")           , "Hidden",      TRUE);
  306.  
  307.                 Release("driving");
  308.                 Mark("driving");
  309.  
  310.                 /* update player nav_cur_city */
  311.                 /* LogStr(LOG_DEBUG,"setting nav cur city:%s\n",CSVGetStr(route_data_id,"city",segment_number)); */
  312.                 ResPropSetStr(Message, "InputText", StrFormatStr("%s %s.",MangleSIDToStr(2/*"You have arrived in"*/), CSVGetStr(route_data_id,"city",segment_number)));
  313.                 ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 10);
  314.                 nav_cur_city = CSVGetStr(route_data_id,"city",segment_number);
  315.                 ResPropSetInt(Player,"nav_cur_city_row_num",CSVSearch(city_data_id,"name",nav_cur_city));
  316.                 
  317.                 
  318.                 /* update the current state */
  319.                 ResParseEvent(ResByName("common/set_cur_state.c4"),"@set_cur_state");                
  320.                   
  321.                 stop;
  322.               }
  323.  
  324.               /* setup next segment */
  325.               /* Log(LOG_DEBUG,"\n going to next segment \n"); */
  326.               segment_number += segment_direction;
  327.               
  328.               /* check if this is a ferry route, and if so show the fullscreen animation. */
  329.               if (CSVGetInt(route_data_id,"show_ferry",segment_number) == 1) {
  330.                 /* load full screen animation */
  331.                 ResPropSetStr(Player, "nav_picture", "ferry");
  332.                 ResPropSetStr(Player, "nav_sound",   "ferry");
  333.                 ResPropSetInt(Player, "nav_picture_no_dash_flag", 1);
  334.                 ResPropSetInt(ResByName("dash.gl/full_screen"), "Hidden", FALSE);
  335.                 state = 11;
  336.                 stop;
  337.               }
  338.  
  339.               /* we are going onto another segement, cause the if above didn't kick in */
  340.               /* Log(LOG_DEBUG,"\n switching state to setup waiting for load \n"); */
  341.               state = -2; /*setup waiting_for_load*/
  342.  
  343.             } else {
  344.             
  345.               cur_frame = ((repeat_number * 16) + frame_number);
  346.             
  347.               /* show some increamenting while we drive in the trip meter */
  348.               segment_distance = StrToInt(CSVGetStr(route_data_id,"distance",segment_number));
  349.               truck_trip_meter = 
  350.                 truck_trip_meter_cached + (
  351.                   (segment_distance * cur_frame) / (32)
  352.                 );
  353.  
  354.               /* add time to the clock */
  355.               time_to_add = segment_distance * 3600;
  356.               time_to_add /= ResPropGetInt(Player,"truck_speed");
  357.               time_to_add /= 32;              
  358.               time_now += time_to_add;
  359.               ResPropSetInt(Player,"time_now",time_now);   
  360.  
  361.               /* compute hunger */ 
  362.               player_hunger += time_to_add;
  363.               
  364.               /* compute fatigue */
  365.               player_fatigue += time_to_add;
  366.               
  367.               /* compute fuel consumption */
  368.               fuel_used = (((segment_distance * 1000) / game_distance_per_fuel_unit) / 32);
  369.               truck_fuel_remaining -= fuel_used;
  370.                            
  371.               /* calculate tire wear */
  372.               ResParseEvent(ResByName("common/calc_tire_wear.c4"),"@calc_tire_wear");  
  373.               
  374.               /* see if we had an accident */
  375.               if (ResPropGetInt(Player,"truck_broken")==1) {
  376.                 
  377.               }              
  378.  
  379.               /* see if we have a flat tire*/
  380.               if (ResPropGetInt(Player,"truck_tire_flat") == 1) {
  381.                 
  382.                 /* stop the truck */
  383.                 ResParseEvent(GuiSiblingByName("brake_pedal"),"@activate");
  384.                 ResParseEvent(GuiSiblingByName("ignition_switch"),"@activate");
  385.  
  386.                 /* tell the user we have a flat */
  387.                 ResPropSetStr(Message, "InputText", MangleSIDToStr(3/*"Oh no! You have a flat tire!"*/));
  388.                 ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  389.                             
  390.                 AudioPlay(ResByName("sound/tire_blowout.wav"));               
  391.                 stop;
  392.               }
  393.  
  394.               
  395.               /* make the map follow the truck */
  396.               if (segment_direction == 1) {
  397.                 xb = StrToInt(CSVGetStr(route_data_id, "xb", segment_number));
  398.                 yb = StrToInt(CSVGetStr(route_data_id, "yb", segment_number));
  399.                 xe = StrToInt(CSVGetStr(route_data_id, "xe", segment_number));
  400.                 ye = StrToInt(CSVGetStr(route_data_id, "ye", segment_number));
  401.               } else {
  402.                 xe = StrToInt(CSVGetStr(route_data_id, "xb", segment_number));
  403.                 ye = StrToInt(CSVGetStr(route_data_id, "yb", segment_number));
  404.                 xb = StrToInt(CSVGetStr(route_data_id, "xe", segment_number));
  405.                 yb = StrToInt(CSVGetStr(route_data_id, "ye", segment_number));
  406.               }
  407.  
  408.               truck_x = xe - xb;
  409.               truck_y = ye - yb;
  410.  
  411.               truck_x *= cur_frame;
  412.               truck_y *= cur_frame;
  413.  
  414.               truck_x /= 32;
  415.               truck_y /= 32;
  416.  
  417.               truck_x += xb;
  418.               truck_y += yb;
  419.               
  420.  
  421.               /* set the truck position in the player object and on the map  and move to front*/
  422.               ActorSetMXMY(ResByName("map.tm/truck"), (truck_x - 5) * 1000,  (truck_y - 5) * 1000 );
  423.              
  424.               view_port_width = ResPropGetInt(GuiSiblingByName("GPS"),"Width") / 2;
  425.               view_port_height = ResPropGetInt(GuiSiblingByName("GPS"),"Height") / 2;
  426.               
  427.               ResPropSetInt(GuiSiblingByName("GPS"),"ScrollX", - (truck_x - view_port_width));
  428.               ResPropSetInt(GuiSiblingByName("GPS"),"ScrollY", - (truck_y - view_port_height));
  429.               
  430.               /* SET THE CURRENTFRAME PROPERTY FOR LEFT_FLICKER, RIGHT_FLICKER, ETC... TO FRAME_NUMBER */
  431.               /* LogStr(LOG_DEBUG,"Setting CurrentFrame to %d\n", frame_number); */
  432.               ResPropSetInt(GuiSiblingByName("left_adorn1") , "CurrentFrame", frame_number);
  433.               ResPropSetInt(GuiSiblingByName("left_flicker") , "CurrentFrame", frame_number);
  434.               ResPropSetInt(GuiSiblingByName("right_flicker") , "CurrentFrame", frame_number);
  435.               ResPropSetInt(GuiSiblingByName("right_adorn1") , "CurrentFrame", frame_number);
  436.               if (repeat_number==0) {
  437.                 ResPropSetInt(GuiSiblingByName("sign") , "CurrentFrame", frame_number);
  438.               }
  439.               ResPropSetInt(GuiSiblingByName("road") , "CurrentFrame", frame_number);
  440.             }
  441.           }
  442.           
  443.           if (state == 7 /*load city scape*/) {
  444.               Release("driving");
  445.               Mark("driving");
  446.  
  447.               /* check if we have arrived at the destination city */
  448.               ResParseEvent(ResByName("common/destination_arrived.c4"),"@destination_arrived");
  449.  
  450.               /* set the at_city, can_eat, can_sleep, can_fuel bits */
  451.               ResPropSetInt(Player,"nav_at_city",1);
  452.               ResPropSetInt(Player,"nav_can_fuel",1);
  453.               ResPropSetInt(Player,"nav_can_eat",1);
  454.               ResPropSetInt(Player,"nav_can_sleep",1);
  455.  
  456.               /* check custom city cellphone crap */
  457.               ResParseEvent(ResByName("common/country_specific.c4"),"@check_custom_order_arrived"); 
  458.  
  459.               /* call the animate event on the load tab, which may set the tab to on */
  460.               ResParseEvent(ResByName("load.tab/can_load_layer/can_load_message"),"@animate");
  461.  
  462.               /* set business open flag */
  463.               ResParseEvent(ResByName("common/set_business_open.c4"),"@set_business_open");
  464.  
  465.               /* set the temperature */
  466.               ResParseEvent(ResByName("common/set_temperature.c4"),"@set_temperature");               
  467.  
  468.               /* if its raining or snowing */
  469.               ResParseEvent(ResByName("common/set_rain_snow.c4"),"@set_rain_snow");                          
  470.  
  471.               /* set night day */
  472.               ResParseEvent(ResByName("common/set_night_day.c4"),"@set_night_day");
  473.  
  474.               /* pickup this cities postcard */
  475.               PlayerPhoto = ResPropGetResID(Player, "photo_city");
  476.               if( StrListAppend(PlayerPhoto,nav_cur_city) ) {
  477.                 ResPropSetStr(Player, "photo_current", nav_cur_city);
  478.                 ResPropSetResID(Player, "photo_current_type", PlayerPhoto);
  479.                 ResPropSetResID(ResByName("postcard.tab/tab"),"AnimationID",ResByName("gui/dash/tab/postcard/postcard_on.pcx"));
  480.               }
  481.            
  482.               /* SKY */
  483.               if (StrExact(time_of_day,"d")) {
  484.                 if (StrExact(precip,"n")) {
  485.                   if (ResPropGetInt(Player, "weather_sky_clarity") < 15) {
  486.                     tmp = "overcast_cab.jpg";
  487.                   } else {
  488.                     if (ResPropGetInt(Player, "weather_sky_clarity") < 30) {
  489.                       tmp = "light_clouds_cab.jpg";
  490.                     } else {
  491.                       tmp = "blue_cab.jpg";
  492.                     }
  493.                   }
  494.                 }
  495.                 if (StrExact(precip,"s")) {
  496.                   tmp = "stormy_cab.jpg";
  497.                 }
  498.                 if (StrExact(precip,"r")) {
  499.                   tmp = "stormy_cab.jpg";
  500.                 }       
  501.               } else {
  502.                 if (StrExact(precip,"n")) {
  503.                   tmp = "stars_cab.jpg";
  504.                 }
  505.                 if (StrExact(precip,"s")) {
  506.                   tmp = "stars_cab.jpg";
  507.                 }
  508.                 if (StrExact(precip,"r")) {
  509.                   tmp = "stars_cab.jpg";
  510.                 }    
  511.               }
  512.               
  513.               /*  set the sky */
  514.               rname = StrFormatStr("anim/sky/%s", tmp);
  515.               restoload = ResByName(rname);
  516.               ResPropSetResID(GuiSiblingByName("sky"), "AnimationID", restoload);
  517.               
  518.  
  519.  
  520.               /* set the city_scape to use */
  521.               tmp = CSVGetStr(city_data_id,"city_scape", CSVSearch(city_data_id,"name",nav_cur_city));
  522.               /* LogStr(LOG_DEBUG,"\n loading city scape:%s\n",StrFormatStr("anim/city_scape/%s_%s%s.anm",tmp, time_of_day, weather)); */
  523.  
  524.  
  525.               if(StrExact("",tmp)) {
  526.                 /* Log(LOG_DEBUG,"\n csv string empty for city scape\n"); */
  527.                 restoload = RES_INVALID;
  528.               } else {
  529.                 restoload = ResByName(StrFormatStr("anim/city_scape/%s_%s%s.pcx",tmp, time_of_day, season));
  530.                 ResPropSetResID(GuiSiblingByName("city_scape") ,"AnimationID", restoload);
  531.               }          
  532.               
  533.               
  534.               /* set the map */
  535.               city_x = StrToInt(CSVGetStr(city_data_id,"X", CSVSearch(city_data_id,"name",nav_cur_city)));
  536.               city_y = StrToInt(CSVGetStr(city_data_id,"Y", CSVSearch(city_data_id,"name",nav_cur_city)));
  537.                                                                                    
  538.               /* set the truck position in the player object and on the map */
  539.               ActorSetMXMY(ResByName("map.tm/truck"), (city_x - 5) * 1000, (city_y - 5) * 1000 );
  540.                             
  541.               truck_x = city_x;
  542.               truck_y = city_y;
  543.               
  544.               view_port_width = ResPropGetInt(GuiSiblingByName("GPS"),"Width") /2;
  545.               view_port_height = ResPropGetInt(GuiSiblingByName("GPS"),"Height") /2;
  546.  
  547.               city_x -= view_port_width;
  548.               city_y -= view_port_height;
  549.               
  550.               /* set the position on the map */              
  551.               ResPropSetInt(GuiSiblingByName("GPS"),"ScrollX", - city_x);
  552.               ResPropSetInt(GuiSiblingByName("GPS"),"ScrollY", - city_y);
  553.  
  554.               /* set real timezone and offset */
  555.               city_row = CSVSearch(city_data_id,"name",nav_cur_city);
  556.               ResPropSetInt(Player,"time_zone_real_offset",CSVGetInt(city_data_id,"timezone_offset",city_row));
  557.               ResPropSetStr(Player,"time_zone_real",CSVGetStr(city_data_id,"timezone",city_row));
  558.             
  559.               /* just for you cliff, highlight the directions that are available on the compass */
  560.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_n",city_row),"-1") ) {              
  561.                 ResPropSetResID(ResByName("dash.gl/N"),"AnimationID",ResByName("gui/dash/compass/highlighted_n.pcx"));
  562.               } else {
  563.                 ResPropSetResID(ResByName("dash.gl/N"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));
  564.               }
  565.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_ne",city_row),"-1") ) {
  566.                 ResPropSetResID(ResByName("dash.gl/NE"),"AnimationID",ResByName("gui/dash/compass/highlighted_ne.pcx"));             
  567.               } else {
  568.                 ResPropSetResID(ResByName("dash.gl/NE"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));                   
  569.               }               
  570.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_e",city_row),"-1") ) {
  571.                 ResPropSetResID(ResByName("dash.gl/E"),"AnimationID",ResByName("gui/dash/compass/highlighted_e.pcx"));      
  572.               } else {
  573.                 ResPropSetResID(ResByName("dash.gl/E"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));                   
  574.               }
  575.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_se",city_row),"-1") ) {
  576.                 ResPropSetResID(ResByName("dash.gl/SE"),"AnimationID",ResByName("gui/dash/compass/highlighted_se.pcx"));         
  577.               } else {
  578.                 ResPropSetResID(ResByName("dash.gl/SE"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));                   
  579.               }
  580.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_s",city_row),"-1") ) {
  581.                 ResPropSetResID(ResByName("dash.gl/S"),"AnimationID",ResByName("gui/dash/compass/highlighted_s.pcx"));        
  582.               } else {
  583.                 ResPropSetResID(ResByName("dash.gl/S"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));                   
  584.               }
  585.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_sw",city_row),"-1") ) {
  586.                 ResPropSetResID(ResByName("dash.gl/SW"),"AnimationID",ResByName("gui/dash/compass/highlighted_sw.pcx"));       
  587.               } else {
  588.                 ResPropSetResID(ResByName("dash.gl/SW"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));                   
  589.               }            
  590.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_w",city_row),"-1") ) {
  591.                 ResPropSetResID(ResByName("dash.gl/W"),"AnimationID",ResByName("gui/dash/compass/highlighted_w.pcx"));       
  592.               } else {
  593.                 ResPropSetResID(ResByName("dash.gl/W"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));                   
  594.               }  
  595.               if ( ! StrExact(CSVGetStr(city_data_id,"seg_nw",city_row),"-1") ) {
  596.                 ResPropSetResID(ResByName("dash.gl/NW"),"AnimationID",ResByName("gui/dash/compass/highlighted_nw.pcx"));    
  597.               } else {
  598.                 ResPropSetResID(ResByName("dash.gl/NW"),"AnimationID",ResByName("gui/dash/compass/invisible.pcx"));                   
  599.               }
  600.               
  601.  
  602.                                          
  603.               state = 0;
  604.               stop;
  605.           }
  606.           
  607.           if (state == 3 /*starting*/) {
  608.               /* Log(LOG_DEBUG,"\n starting \n"); */
  609.        
  610.               Release("driving");
  611.               Mark("driving");
  612.  
  613.               frame_number = 0;
  614.               repeat_number = 0;
  615.  
  616.               /* set the at_city, can_eat, can_sleep, can_fuel bits */
  617.               ResPropSetInt(Player,"nav_at_city",0);
  618.               ResPropSetInt(Player,"nav_can_fuel",0);
  619.               ResPropSetInt(Player,"nav_can_eat",0);
  620.               ResPropSetInt(Player,"nav_can_sleep",0);
  621.  
  622.               /* clear the city scape */
  623.               ResPropSetResID(GuiSiblingByName("city_scape"), "AnimationID", RES_INVALID);
  624.  
  625.               /* set the trip meter to its corrected position */
  626.               truck_trip_meter_cached = truck_trip_meter;
  627.                            
  628.               /* segment number should have been set by whatever set the state to starting */
  629.  
  630.               /* set segment_direction to zero, it will be set in state -2 below if it is zero */
  631.               segment_direction = 0;
  632.               /* LogStr(LOG_DEBUG,"\n switching state to setup waiting for load. Segment #%d\n", segment_number); */
  633.               state = -2; /*setup waiting_for_load*/
  634.           }
  635.           
  636.           
  637.           if (state == -2/*setup waiting_for_load*/) {
  638.  
  639.               Release("driving");
  640.               Mark("driving");
  641.  
  642.               /* Log(LOG_DEBUG,"\n loading segment \n"); */
  643.                             
  644.               /* convert to: begin = 0, middle = 1, end = 2 */
  645.               if(StrExact(CSVGetStr(route_data_id,"type",segment_number),"B")) {
  646.                 /* Log(LOG_DEBUG,"\n segment type set to beginning \n"); */
  647.                 segment_type = 0;
  648.               }
  649.               if(StrExact(CSVGetStr(route_data_id,"type",segment_number),"M")) {
  650.                 /* Log(LOG_DEBUG,"\n segment type set to middle \n");  */           
  651.                 segment_type = 1;
  652.               } 
  653.               if(StrExact(CSVGetStr(route_data_id,"type",segment_number),"E")) {
  654.                 /* Log(LOG_DEBUG,"\n segment type set to end \n");  */            
  655.                 segment_type = 2;
  656.               }
  657.  
  658.  
  659.               if (segment_direction==0) {
  660.                 if (segment_type==0) {
  661.                   segment_direction = 1;
  662.                 } else {
  663.                   if (segment_type==1) {
  664.                    /* Log(LOG_DEBUG, "Doh!, starting in the middle of a segment\n"); */
  665.                     segment_direction = 1;
  666.                   } else {
  667.                     if (segment_type==2) {
  668.                       segment_direction = -1;
  669.                     }
  670.                   }
  671.                 }
  672.               }
  673.  
  674.              
  675.               /* pickup this postcard */
  676.               postcard = CSVGetStr(route_data_id,"postcard",segment_number);
  677.               if (! StrExact(postcard,"")) {
  678.                 PlayerPhoto = ResPropGetResID(Player, "photo_postcard");              
  679.                 if( StrListAppend(PlayerPhoto,postcard) ) {
  680.                   AudioPlay(ResByNAme("sound/camera_shutter.wav"));                
  681.                   ResPropSetStr(Player, "photo_current", postcard);
  682.                   ResPropSetResID(Player, "photo_current_type", PlayerPhoto);
  683.                   ResPropSetResID(ResByName("postcard.tab/tab"),"AnimationID",ResByName("gui/dash/tab/postcard/postcard_on.pcx"));
  684.                 }
  685.               }
  686.               
  687.               /* set night day */
  688.               ResParseEvent(ResByName("common/set_night_day.c4"),"@set_night_day");
  689.  
  690.               /* set the temperature */
  691.               ResParseEvent(ResByName("common/set_temperature.c4"),"@set_temperature");               
  692.  
  693.               /* if its raining or snowing */
  694.               ResParseEvent(ResByName("common/set_rain_snow.c4"),"@set_rain_snow");                          
  695.  
  696.  
  697.               /* See if we can stop for food */
  698.               if (StrExact(CSVGetStr(route_data_id,"can_eat",segment_number),"")) {
  699.                 ResPropSetInt(Player,"nav_can_eat",0);
  700.               } else {
  701.                 ResPropSetInt(Player,"nav_can_eat",1);
  702.               }
  703.  
  704.               /* See if we can stop to sleep */
  705.               if (StrExact(CSVGetStr(route_data_id,"can_sleep",segment_number),"")) {
  706.                 ResPropSetInt(Player,"nav_can_sleep",0);
  707.               } else {
  708.                 ResPropSetInt(Player,"nav_can_sleep",1);
  709.               }
  710.               
  711.               /* See if we can stop to get fuel */
  712.               if (StrExact(CSVGetStr(route_data_id,"can_fuel",segment_number),"")) {
  713.                 ResPropSetInt(Player,"nav_can_fuel",0);
  714.               } else {
  715.                 ResPropSetInt(Player,"nav_can_fuel",1);
  716.               }
  717.  
  718.               /* SIGN */
  719.               sign_type = CSVGetStr(route_data_id, "sign_type", segment_number);
  720.  
  721.               if ( StrExact(sign_type,"d") && (segment_direction==1) && (segment_type != 2)) {
  722.                 /* sign leaving */
  723.                 tmp2_int = CSVGetInt(route_data_id,"distance",segment_number);
  724.                 tmp_int = segment_number+1;
  725.                 while(!StrExact(CSVGetStr(route_data_id,"type",tmp_int),"E")) {
  726.                   tmp2_int += CSVGetInt(route_data_id, "distance", tmp_int);
  727.                   tmp_int+=1;
  728.                 }
  729.                 tmp2_int += CSVGetInt(route_data_id, "distance", tmp_int);
  730.                 tmp = CSVGetStr(route_data_id,"city",tmp_int);
  731.                 
  732.                 ResPropSetStr(
  733.                   GuiSiblingByName("sign"), "signtext",
  734.                   StrFormatStr("%s\n%d %s", tmp, tmp2_int, ResPropGetStr(Game, "game_distance_unit"))
  735.                 );
  736.  
  737.                 if (StrExact(time_of_day, "d")) {
  738.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_day.anm"));
  739.                 } else {
  740.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_night.anm"));
  741.                 }
  742.               }
  743.  
  744.               if ( StrExact(sign_type, "d") && (segment_direction==-1) && (segment_type != 0)) {
  745.                 /* sign leaving */
  746.                 tmp2_int = CSVGetInt(route_data_id,"distance",segment_number);
  747.                 tmp_int = segment_number-1;
  748.                 while(!StrExact(CSVGetStr(route_data_id,"type",tmp_int),"B")) {
  749.                   tmp2_int += CSVGetInt(route_data_id, "distance", tmp_int);
  750.                   tmp_int-=1;
  751.                 }
  752.                 tmp = CSVGetStr(route_data_id,"city",tmp_int);
  753.                 tmp2_int += CSVGetInt(route_data_id, "distance", tmp_int);
  754.                 
  755.                 ResPropSetStr(
  756.                   GuiSiblingByName("sign"), "signtext",
  757.                   StrFormatStr("%s\n%d %s", tmp, tmp2_int, ResPropGetStr(Game, "game_distance_unit"))
  758.                 );
  759.  
  760.                 if (StrExact(time_of_day, "d")) {
  761.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_day.anm"));
  762.                 } else {
  763.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_night.anm"));
  764.                 }
  765.               }
  766.  
  767.               if ( StrExact(sign_type, "d") &&
  768.                    (((segment_type==2) && (segment_direction== 1)) ||
  769.                     ((segment_type==0) && (segment_direction==-1)))
  770.                  ) {
  771.                  
  772.                 /* sign arriving */
  773.                 tmp = CSVGetStr(route_data_id,"city",segment_number);
  774.                 tmp2 = CSVGetStr(city_data_id,"population", CSVSearch(city_data_id, "name", tmp));
  775.                 
  776.                 ResPropSetStr(
  777.                   GuiSiblingByName("sign"), "signtext",
  778.                   StrFormatStr("%s\npop. %s", tmp, tmp2)
  779.                 );
  780.  
  781.                 if (StrExact(time_of_day, "d")) {
  782.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_day.anm"));
  783.                 } else {
  784.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_night.anm"));
  785.                 }
  786.               }
  787.  
  788.               if ( StrExact(sign_type, "p") && (!StrExact(postcard,"")) ) {
  789.                 ResPropSetStr( GuiSiblingByName("sign"), "signtext", CSVGetStr(route_data_id,"sign_text",segment_number) );
  790.  
  791.                 if (StrExact(time_of_day, "d")) {
  792.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_day.anm"));
  793.                 } else {
  794.                   ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName("anim/sign/sign_night.anm"));
  795.                 }
  796.               }
  797.  
  798.               if ( StrExact(sign_type, "s") ) {
  799.                 tmp_int = CSVGetInt(route_data_id, "speed_limit", segment_number);
  800.                 ResPropSetStr( GuiSiblingByName("sign"), "signtext", "");
  801.  
  802.                 if (StrExact(time_of_day, "d")) {
  803.                   tmp = StrFormatStr("anim/speed_limit/speed_limit_%d/speedlimit_%d_day.anm", tmp_int, tmp_int);
  804.                 } else {
  805.                   tmp = StrFormatStr("anim/speed_limit/speed_limit_%d/speedlimit_%d_night.anm", tmp_int, tmp_int);
  806.                 }
  807.                 ResPropSetResID(GuiSiblingByName("sign"), "AnimationID", ResByName(tmp));
  808.               }
  809.  
  810.               /* SKY */
  811.               if (StrExact(time_of_day,"d")) {
  812.                 if (StrExact(precip,"n")) {
  813.                   if (ResPropGetInt(Player, "weather_sky_clarity") < 15) {
  814.                     tmp = "overcast_cab.jpg";
  815.                   } else {
  816.                     if (ResPropGetInt(Player, "weather_sky_clarity") < 30) {
  817.                       tmp = "light_clouds_cab.jpg";
  818.                     } else {
  819.                       tmp = "blue_cab.jpg";
  820.                     }
  821.                   }
  822.                 }
  823.                 if (StrExact(precip,"s")) {
  824.                   tmp = "stormy_cab.jpg";
  825.                 }
  826.                 if (StrExact(precip,"r")) {
  827.                   tmp = "stormy_cab.jpg";
  828.                 }       
  829.               } else {
  830.                 if (StrExact(precip,"n")) {
  831.                   tmp = "stars_cab.jpg";
  832.                 }
  833.                 if (StrExact(precip,"s")) {
  834.                   tmp = "stars_cab.jpg";
  835.                 }
  836.                 if (StrExact(precip,"r")) {
  837.                   tmp = "stars_cab.jpg";
  838.                 }    
  839.               }
  840.                 
  841.               rname = StrFormatStr("anim/sky/%s", tmp);
  842.               restoload = ResByName(rname);
  843.               ResPropSetResID(GuiSiblingByName("sky"), "AnimationID", restoload);
  844.  
  845.               
  846.               /* ROAD */
  847.               if ( ResPropGetInt(Player,"truck_light") == 1 ) {
  848.                 head_light_flag = "l";
  849.               } else {
  850.                 head_light_flag = "u";
  851.               }              
  852.              
  853.               tmp = CSVGetStr(route_data_id,"road",segment_number);
  854.               if(StrExact("",tmp)) {
  855.                 /* Log(LOG_DEBUG,"\n csv string empty for road \n"); */
  856.                 restoload = RES_INVALID;
  857.               } else {
  858.  
  859.                 /* Log(LOG_DEBUG,"\n loading  road\n"); */
  860.                 if (StrExact("", weather)) {
  861.                   /* Log(LOG_DEBUG,"\n WEATHER NOT SET!\n"); */
  862.                   weather = "d";
  863.                 }
  864.                 rname = StrFormatStr("anim/road/%s_%s%s%s.anm", tmp, time_of_day, weather, head_light_flag);
  865.                 restoload = ResByName(rname);
  866.                 ResPropSetResID(GuiSiblingByName("road") , "AnimationID", restoload);
  867.                 ResPropSetInt(GuiSiblingByName("road") , "Hidden", FALSE);
  868.  
  869.               }
  870.  
  871.  
  872.               /* HORIZON */
  873.               tmp = CSVGetStr(route_data_id, "horizon", segment_number);
  874.               if(StrExact("",tmp)) {
  875.                 /* Log(LOG_DEBUG,"\n csv string empty for horizon\n"); */
  876.                 restoload = RES_INVALID;
  877.               } else {
  878.                 /* Log(LOG_DEBUG,"\n loading  horizon \n"); */
  879.                 rname = StrFormatStr("anim/horizon/%s/%s_%s%s.pcx", tmp, tmp, time_of_day, season);
  880.                 restoload = ResByName(rname);
  881.                 ResPropSetResID(GuiSiblingByName("horizon") , "AnimationID", restoload);
  882.               }
  883.  
  884.               /* setup flickers, sky, road, etc... */
  885.               if (segment_direction==1/*forward*/) {
  886.                   /* LEFT FLICKER */
  887.                   tmp = CSVGetStr(route_data_id,"left_flicker",segment_number);
  888.                   if(StrExact("",tmp)) {
  889.                     /* Log(LOG_DEBUG,"\n csv string empty for left flicker \n"); */
  890.                     restoload = RES_INVALID;
  891.                   } else {
  892.                     /* Log(LOG_DEBUG,"\n loading  left flicker \n"); */
  893.                     rname = StrFormatStr("anim/flicker/%s/%s_l%s%s.anm", tmp, tmp, time_of_day, season);
  894.                     restoload = ResByName(rname);
  895.                     ResPropSetResID(GuiSiblingByName("left_flicker") , "AnimationID", restoload);
  896.                   }
  897.  
  898.                   /* LEFT ADORN 1 */              
  899.                   tmp = CSVGetStr(route_data_id,"left_adorn1",segment_number);
  900.                   if(StrExact("",tmp)) {
  901.                     /* Log(LOG_DEBUG,"\n csv string empty for left adorn1 \n"); */
  902.                     restoload = RES_INVALID;
  903.                   } else {
  904.                     /* Log(LOG_DEBUG,"\n loading left adorn1 \n"); */
  905.                     rname = StrFormatStr("anim/adornment/%s/%s_l%s%s.anm", tmp, tmp, time_of_day, season);
  906.                     ResPropSetInt(SELF, "adorn1_left_play_once", CSVGetInt(adorn_data_id, "play_once", CSVSearch(adorn_data_id,"name", tmp)));
  907.                     restoload = ResByName(rname);
  908.                     ResPropSetResID(GuiSiblingByName("left_adorn1") , "AnimationID", restoload);
  909.                   }
  910.     
  911.                   
  912.                  /* RIGHT ADORN 1 */              
  913.                   tmp = CSVGetStr(route_data_id,"right_adorn1",segment_number);
  914.                   if(StrExact("",tmp)) {
  915.                     /* Log(LOG_DEBUG,"\n csv string empty for right adorn1 \n"); */
  916.                     restoload = RES_INVALID;
  917.                   } else {
  918.                     /* Log(LOG_DEBUG,"\n loading right adorn1 \n"); */
  919.                     rname = StrFormatStr("anim/adornment/%s/%s_r%s%s.anm", tmp, tmp, time_of_day, season);
  920.                     ResPropSetInt(SELF, "adorn1_right_play_once", CSVGetInt(adorn_data_id, "play_once", CSVSearch(adorn_data_id,"name", tmp)));
  921.                     restoload = ResByName(rname);
  922.                     ResPropSetResID(GuiSiblingByName("right_adorn1") , "AnimationID", restoload);
  923.                   }
  924.                   
  925.                   /* RIGHT FLICKER */              
  926.                   tmp = CSVGetStr(route_data_id,"right_flicker",segment_number);
  927.                   if(StrExact("",tmp)) {
  928.                     /* Log(LOG_DEBUG,"\n csv string empty for right flicker \n"); */
  929.                     restoload = RES_INVALID;
  930.                   } else {
  931.                     /* Log(LOG_DEBUG,"\n loading right flicker \n"); */
  932.                     rname = StrFormatStr("anim/flicker/%s/%s_r%s%s.anm", tmp, tmp, time_of_day, season);
  933.                     restoload = ResByName(rname);
  934.                     ResPropSetResID(GuiSiblingByName("right_flicker") , "AnimationID", restoload);
  935.                   }
  936.               } else {
  937.                   /* LEFT FLICKER */
  938.                   tmp = CSVGetStr(route_data_id,"right_flicker",segment_number);
  939.                   if(StrExact("",tmp)) {
  940.                     /* Log(LOG_DEBUG,"\n csv string empty for left flicker \n"); */
  941.                     restoload = RES_INVALID;
  942.                   } else {
  943.                     /* Log(LOG_DEBUG,"\n loading  left flicker \n"); */
  944.                     rname = StrFormatStr("anim/flicker/%s/%s_l%s%s.anm", tmp, tmp, time_of_day, season);
  945.                     restoload = ResByName(rname);
  946.                     ResPropSetResID(GuiSiblingByName("left_flicker") , "AnimationID", restoload);
  947.                   }
  948.                   
  949.                   /* LEFT ADORN 1 */              
  950.                   tmp = CSVGetStr(route_data_id,"right_adorn1",segment_number);
  951.                   if(StrExact("",tmp)) {
  952.                     /* Log(LOG_DEBUG,"\n csv string empty for left adorn1 \n"); */
  953.                     restoload = RES_INVALID;
  954.                   } else {
  955.                     /* Log(LOG_DEBUG,"\n loading left adorn1 \n"); */
  956.                     rname = StrFormatStr("anim/adornment/%s/%s_l%s%s.anm", tmp, tmp, time_of_day, season);
  957.                     ResPropSetInt(SELF, "adorn1_left_play_once", CSVGetInt(adorn_data_id, "play_once", CSVSearch(adorn_data_id,"name", tmp)));
  958.                     restoload = ResByName(rname);
  959.                     ResPropSetResID(GuiSiblingByName("left_adorn1") , "AnimationID", restoload);
  960.                   }
  961.     
  962.     
  963.                   
  964.                  /* RIGHT ADORN 1 */              
  965.                   tmp = CSVGetStr(route_data_id,"left_adorn1",segment_number);
  966.                   if(StrExact("",tmp)) {
  967.                     /* Log(LOG_DEBUG,"\n csv string empty for right adorn1 \n"); */
  968.                     restoload = RES_INVALID;
  969.                   } else {
  970.                     /* Log(LOG_DEBUG,"\n loading right adorn1 \n"); */
  971.                     rname = StrFormatStr("anim/adornment/%s/%s_r%s%s.anm", tmp, tmp, time_of_day, season);
  972.                     ResPropSetInt(SELF, "adorn1_right_play_once", CSVGetInt(adorn_data_id, "play_once", CSVSearch(adorn_data_id,"name", tmp)));
  973.                     restoload = ResByName(rname);
  974.                     ResPropSetResID(GuiSiblingByName("right_adorn1") , "AnimationID", restoload);
  975.                   }
  976.                   
  977.  
  978.                   /* RIGHT FLICKER */              
  979.                   tmp = CSVGetStr(route_data_id,"left_flicker",segment_number);
  980.                   if(StrExact("",tmp)) {
  981.                     /* Log(LOG_DEBUG,"\n csv string empty for right flicker \n"); */
  982.                     restoload = RES_INVALID;
  983.                   } else {
  984.                     /* Log(LOG_DEBUG,"\n loading right flicker \n"); */
  985.                     rname = StrFormatStr("anim/flicker/%s/%s_r%s%s.anm", tmp, tmp, time_of_day, season);
  986.                     restoload = ResByName(rname);
  987.                     ResPropSetResID(GuiSiblingByName("right_flicker") , "AnimationID", restoload);
  988.                   }
  989.  
  990.               }
  991.           
  992.  
  993.                /* id of last thing to be ResByNamed */
  994.               ResPropSetResID(SELF, "load_watch_id", ResPropGetResID(GuiSiblingByName("right_flicker"), "AnimationID"));
  995.               
  996.               /* Log(LOG_DEBUG,"\n switching state to waiting for load \n"); */
  997.               state = 2;
  998.           }
  999.  
  1000.           if (state == 4 /*pause*/ ) {
  1001.             /* for each flicker sky road, etc... pause it */
  1002.             /* Log(LOG_DEBUG,"\n switching state to paused \n"); */
  1003.             state = 5 /* paused */;
  1004.             stop;
  1005.           }
  1006.           
  1007.           if (state == 6 /*unpause*/ ) {
  1008.             /* for each flicker sky road, etc... unpause it */
  1009.             /* Log(LOG_DEBUG,"\n switching state to running \n"); */
  1010.             state = 1 /* running */;
  1011.             stop;
  1012.           }
  1013.           
  1014.           if (state == 8 /* tow truck */ ) {          
  1015.             
  1016.             /* show the tow truck animation and play it */
  1017.             if (ResPropGetInt(GuiSiblingByName("tow_truck"),"Hidden") == 1) {
  1018.  
  1019.               Mark("tow_truck"); 
  1020.  
  1021.               AudioPlay(ResByName("sound/tow_truck.wav"));
  1022.               if (StrExact(time_of_day,"d")) {
  1023.                 ResPropSetResID(ResByName("dash.gl/tow_truck"),"AnimationID", ResByName("anim/towtruck/towtruck_day.anm"));
  1024.               } else {
  1025.                 ResPropSetResID(ResByName("dash.gl/tow_truck"),"AnimationID", ResByName("anim/towtruck/towtruck_night.anm"));
  1026.               }
  1027.               ResParseEvent(GuiSiblingByName("brake_pedal"),"@activate");
  1028.               ResPropSetInt(GuiSiblingByName("tow_truck"),"Hidden", FALSE);
  1029.               ResPropSetInt(GuiSiblingByName("tow_truck"),"CurrentFrame", 0);
  1030.               ResPropSetInt(GuiSiblingByName("tow_truck"),"State", PLAYING);
  1031.               ResPropSetInt(GuiSiblingByName("tow_truck"),"Loop", FALSE);
  1032.             }
  1033.  
  1034.             if (ResPropGetInt(GuiSiblingByName("tow_truck"),"CurrentFrame") == 100) {
  1035.               ResPropAlias(Player,"expense_spent_on_mishap","expense_spent_on_mishap");
  1036.             
  1037.               if (ResPropGetInt(Player,"truck_tire_flat") == 1) {
  1038.                 ResPropSetStr(Message, "InputText", MangleSIDToStr(4/*"The tow truck driver fixed your flat tire and charged you $30."*/));
  1039.                 ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 4);
  1040.                 ResPropSetInt(Player,"truck_tire_flat",0);     
  1041.                 ResPropSetResID(ResByName("maintenance.tab/tab"),"AnimationID",ResByName("gui/dash/tab/maintenance/maintenance_off.pcx"));  
  1042.                 expense_spent_on_mishap += 3000;
  1043.               }
  1044.  
  1045.               if (ResPropGetInt(Player,"truck_broken") == 1) {
  1046.                 ResPropSetStr(Message, "InputText", MangleSIDToStr(5/*"The tow truck driver repaired your truck and charged you $200."*/));
  1047.                 ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 4);
  1048.                 ResPropSetInt(Player,"truck_broken",0);
  1049.                 ResPropSetInt(GuiSiblingByName("accident"),"Hidden",TRUE);
  1050.                 expense_spent_on_mishap += 20000;
  1051.               }
  1052.      
  1053.               if (truck_fuel_remaining <= 0) {
  1054.                 ResPropSetStr(Message, "InputText", MangleSIDToStr(6/*"The tow truck driver gave you some fuel and charged you $50."*/));
  1055.                 ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 4);
  1056.                 truck_fuel_remaining = 30000;
  1057.                 expense_spent_on_mishap += 5000;               
  1058.               }
  1059.             }
  1060.               
  1061.  
  1062.             /* if all the frames have been played then hide it. set state to paused */
  1063.             if ((ResPropGetInt(GuiSiblingByName("tow_truck"),"FrameCount") -1 ) ==
  1064.                  ResPropGetInt(GuiSiblingByName("tow_truck"),"CurrentFrame")) {
  1065.               ResPropSetInt(GuiSiblingByName("tow_truck"),"Hidden", TRUE);
  1066.               state = 4;
  1067.               Release("tow_truck");             
  1068.               CVarSetInt("guiInputEnabled",1);
  1069.             }
  1070.           }
  1071.  
  1072.           if (state == 9 /* police */ ) {
  1073.                
  1074.             /* show the tow truck animation and play it */
  1075.             if (ResPropGetInt(GuiSiblingByName("police"),"Hidden") == 1) {
  1076.             
  1077.               Mark("cop");   
  1078.             
  1079.               CVarSetInt("guiInputEnabled",0);
  1080.               ResParseEvent(GuiSiblingByName("ignition_switch"),"@activate");
  1081.               
  1082.               AudioStop(ResPropGetInt(Player,"truck_siren_loop_sound_id"));
  1083.               ResPropSetInt(Player,"truck_siren_loop_sound_id",AudioPlayLooped(ResByName("sound/siren_loop.wav")));
  1084.               
  1085.               if (StrExact(time_of_day,"d")) {
  1086.                 ResPropSetResID(ResByName("dash.gl/police"),"AnimationID", ResByName("anim/cop/cop_day.anm"));
  1087.               } else {
  1088.                 ResPropSetResID(ResByName("dash.gl/police"),"AnimationID", ResByName("anim/cop/cop_night.anm"));
  1089.               }
  1090.               AudioStop(ResPropGetInt(Player,"truck_siren_loop_sound_id"));
  1091.               AudioStop(ResPropGetInt(Player,"truck_siren_doppler_sound_id"));
  1092.               ResPropSetInt(Player,"truck_siren_doppler_sound_id",AudioPlay(ResByName("sound/siren_doppler.wav")));
  1093.               
  1094.               ResPropSetInt(GuiSiblingByName("police"),"Hidden", FALSE);
  1095.               ResPropSetInt(GuiSiblingByName("police"),"CurrentFrame", 0);              
  1096.               ResPropSetInt(GuiSiblingByName("police"),"State", PLAYING);
  1097.               ResPropSetInt(GuiSiblingByName("police"),"Loop", FALSE);
  1098.             }
  1099.  
  1100.             if (ResPropGetInt(GuiSiblingByName("police"),"CurrentFrame") == 100) {
  1101.               ResPropAlias(Player,"expense_spent_on_ticket","expense_spent_on_ticket");            
  1102.               
  1103.               tmp = StrFormatStr(MangleSIDToStr(355/*"You have been pulled over in %s."*/),ResPropGetStr(Player,"nav_cur_state"));
  1104.  
  1105.               if (ResPropGetInt(Player,"truck_speeding") == 1) {
  1106.                 tmp_int = CSVGetInt(state_data_id,"speed_fine",ResPropGetInt(Player,"nav_cur_state_row_num"));
  1107.                 tmp = StrFormatStr(MangleSIDToStr(7/*"%s The fine for speeding here is $%d."*/),tmp,tmp_int);
  1108.                 expense_spent_on_ticket += tmp_int * 100;
  1109.               }
  1110.  
  1111.               if (ResPropGetInt(Player,"truck_seatbelt") == 0) {
  1112.                 tmp_int = CSVGetInt(state_data_id,"seatbelt_fine",ResPropGetInt(Player,"nav_cur_state_row_num"));
  1113.                 tmp = StrFormatStr(MangleSIDToStr(8/*"%s The fine for not wearing your seat belt here is $%d."*/),tmp,tmp_int);
  1114.                 expense_spent_on_ticket += tmp_int * 100;
  1115.               }
  1116.  
  1117.               if ((ResPropGetInt(Player,"truck_chains_on") == 1) && StrExact(precip,"n")) {
  1118.                 tmp_int = ResPropGetInt(Game,"game_fine_chains");
  1119.                 tmp = StrFormatStr(MangleSIDToStr(9/*"%s The fine for improper use of chains here is $%d."*/),tmp,tmp_int);
  1120.                 expense_spent_on_ticket += tmp_int * 100;
  1121.               }
  1122.               ResPropSetStr(Message, "InputText",tmp);
  1123.               ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 30);
  1124.               
  1125.             }
  1126.  
  1127.             /* if all the frames have been played then hide it. set state to paused */
  1128.             if ((ResPropGetInt(GuiSiblingByName("police"),"FrameCount") -1 ) ==
  1129.                  ResPropGetInt(GuiSiblingByName("police"),"CurrentFrame")) {   
  1130.               ResPropSetInt(GuiSiblingByName("police"),"Hidden", TRUE);
  1131.               state = 4;
  1132.               Release("cop");              
  1133.               CVarSetInt("guiInputEnabled",1);
  1134.             
  1135.             }
  1136.           }
  1137.  
  1138.  
  1139.           
  1140.           if (state == 10 /* accident */ ) {
  1141.             /* show the accident animation and play it */
  1142.             ResPropAlias(Player,"expense_spent_on_mishap","expense_spent_on_mishap");
  1143.                           
  1144.             if (ResPropGetInt(GuiSiblingByName("accident"),"Hidden") == 1) {
  1145.               if (StrExact(time_of_day,"d")) {
  1146.                 ResPropSetResID(ResByName("dash.gl/accident"),"AnimationID", ResByName("anim/accident/accident_day.anm"));
  1147.               } else {
  1148.                 ResPropSetResID(ResByName("dash.gl/accident"),"AnimationID", ResByName("anim/accident/accident_night.anm"));
  1149.               }
  1150.               
  1151.               AudioPlay(ResByName("sound/accident.wav"));
  1152.               ResPropSetInt(GuiSiblingByName("accident"),"Hidden", FALSE);
  1153.               ResPropSetInt(GuiSiblingByName("accident"),"CurrentFrame", 0);              
  1154.               ResPropSetInt(GuiSiblingByName("accident"),"State", PLAYING);
  1155.               ResPropSetInt(GuiSiblingByName("accident"),"Loop", FALSE);
  1156.               ResPropSetStr(Message, "InputText", ResPropGetStr(Player,"nav_accident_message"));
  1157.               ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 10);
  1158.               ResPropSetStr(Player,"nav_accident_message","");
  1159.             }
  1160.  
  1161.             /* if all the frames have been played. set state to paused */
  1162.             if ((ResPropGetInt(GuiSiblingByName("accident"),"FrameCount") -1 ) ==
  1163.                  ResPropGetInt(GuiSiblingByName("accident"),"CurrentFrame")) {   
  1164.               state = 4;
  1165.               CVarSetInt("guiInputEnabled",1);
  1166.             }
  1167.           }
  1168.           
  1169.           if (state == 11 /* ferry */ ) {
  1170.             if ( ResPropGetInt(GuiSiblingByName("full_screen"),"Hidden") == 1) {
  1171.               repeat_number = 2;
  1172.               state = 1;
  1173.               ResParseEvent(GuiSiblingByName("ignition_switch"),"@activate");
  1174.               ResPropSetInt(Player, "truck_running", 1);
  1175.               ResPropSetInt(GuiSiblingByName("gas_pedal"), "pedal_state", 1);
  1176.             }
  1177.  
  1178.           } /* end ferry if */     
  1179.  
  1180.         }
  1181.       }
  1182.     },
  1183.     GuiAnimation("sky") {
  1184.       X = 0;
  1185.       Y = 20;
  1186.     },
  1187.     GuiAnimation("horizon") {
  1188.       X = 0;
  1189.       Y = 0;
  1190.     },
  1191.     GuiAnimation("left_flicker") {
  1192.       X = -13;
  1193.       Y = 0;
  1194.       State = STOPPED;
  1195.     
  1196.     },
  1197.     
  1198.     GuiAnimation("right_flicker") {
  1199.       X = 314;
  1200.       Y = 0;
  1201.       State = STOPPED;      
  1202.     },
  1203.  
  1204.     GuiAnimation("road") {
  1205.       X = 0;
  1206.       Y = 150;
  1207.       State = STOPPED;
  1208.     },
  1209.  
  1210.     GuiAnimation("left_adorn1") {
  1211.       X = -13;
  1212.       Y = 0;
  1213.       State = STOPPED;
  1214.     },
  1215.  
  1216.     GuiAnimation("right_adorn1") {
  1217.       X = 314;
  1218.       Y = 0;
  1219.       State = STOPPED;
  1220.     },
  1221.     
  1222.     GuiSign("sign") {
  1223.       X = 321;
  1224.       Y = -29;
  1225.       State = STOPPED;
  1226.       ScriptID = Script {
  1227.         @loaded {
  1228.           ResByName("font/arial_06.tf");
  1229.           ResByName("font/arial_08.tf");
  1230.           ResByName("font/arial_16.tf");
  1231.         }
  1232.         @draw {
  1233.           int frame;
  1234.           int x;
  1235.           int y;
  1236.           str text;
  1237.           if(!ResValid(ResPropGetResID(SELF, "AnimationID"))) { stop; }
  1238.           frame = ResPropGetInt(SELF,"CurrentFrame");
  1239.           if (frame<10) {stop;}
  1240.           text = ResPropGetStr(SELF,"signtext");
  1241.           x = ResPropGetInt(SELF,"ScreenX");
  1242.           y = ResPropGetInt(SELF,"ScreenY");
  1243.           if (frame==13) {
  1244.             DrawTextRectStr(
  1245.               ResByName("font/arial_06.tf"),
  1246.               x+40,
  1247.               y+146,
  1248.               49,
  1249.               18,
  1250.               "%s",
  1251.               text
  1252.             );
  1253.             stop;
  1254.           }
  1255.           if (frame==14) {
  1256.             DrawTextRectStr(
  1257.               ResByName("font/arial_10.tf"),
  1258.               x+50,
  1259.               y+133,
  1260.               68,
  1261.               28,
  1262.               "%s",
  1263.               text
  1264.             );
  1265.             stop;
  1266.           }
  1267.           if (frame==15) {
  1268.             DrawTextRectStr(
  1269.               ResByName("font/arial_16.tf"),
  1270.               x+73,
  1271.               y+107,
  1272.               120,
  1273.               46,
  1274.               "%s",
  1275.               text
  1276.             );
  1277.             stop;
  1278.           }
  1279.         }
  1280.       }
  1281.     },    
  1282.     GuiAnimation("tow_truck") {
  1283.       X = -5;
  1284.       Y = -25;
  1285.       Hidden = TRUE;
  1286.       State = STOPPED;
  1287.     },
  1288.     GuiAnimation("police") {
  1289.       X = 0;
  1290.       Y = -17;
  1291.       Hidden = TRUE;
  1292.       State = STOPPED;
  1293.     },
  1294.     
  1295.     GuiAnimation("city_scape") {
  1296.       X = 0;
  1297.       Y = 0;
  1298.     },
  1299.     
  1300.     GuiAnimation("in_dash") {
  1301.       Hidden = TRUE;
  1302.       X = 0;
  1303.       Y = 0;
  1304.     },
  1305.  
  1306.     GuiParticleSystem("rain_in_dash") {
  1307.       Hidden = TRUE;
  1308.       X = 0;
  1309.       Y = 45;
  1310.       Width = 640;
  1311.       Height = 210;
  1312.       ParticleSystemID = ParticleSystem("rid") {
  1313.         EmitterType = LINE_HORIZONTAL;
  1314.         EmitterX = 0;
  1315.         EmitterY = -50;
  1316.         EmitterWidth = 640;
  1317.         EmitterHeight = 480;
  1318.         AnimationID = "anim/particle/rain.pcx";
  1319.         BirthRate = 3;
  1320.         BirthRateVariation = 0;
  1321.         VelMX = 2000;
  1322.         VelMXVariation = 1000;
  1323.         VelMY = 30000;
  1324.         VelMYVariation = 3000;
  1325.         Life = 8;
  1326.         LifeVariation = 0;
  1327.         LeadTime = 0;
  1328.       }
  1329.     },
  1330.      
  1331.     
  1332.     GuiParticleSystem("snow_in_dash") {
  1333.       Hidden = TRUE;    
  1334.       X = 0;
  1335.       Y = 45;
  1336.       Width = 640;
  1337.       Height = 210;
  1338.       ParticleSystemID = ParticleSystem("sid") {
  1339.         EmitterType = LINE_HORIZONTAL;
  1340.         EmitterX = 0;
  1341.         EmitterY = -50;
  1342.         EmitterWidth = 640;
  1343.         EmitterHeight = 480;
  1344.         AnimationID = "anim/particle/snow.pcx";
  1345.         BirthRate = 3;
  1346.         BirthRateVariation = 0;
  1347.         VelMX = 2000;
  1348.         VelMXVariation = 1000;
  1349.         VelMY = 10000;
  1350.         VelMYVariation = 1000;
  1351.         Life = 28;
  1352.         LifeVariation = 0;
  1353.         LeadTime = 0;
  1354.       }
  1355.     },
  1356.     
  1357.     
  1358.     GuiAnimation("wiper") {
  1359.       AnimationID = "gui/dash/wipers/day/wipers.anm";
  1360.       X = 50;
  1361.       Y = 0;
  1362.       State = STOPPED;
  1363.     },
  1364.     
  1365.     GuiAnimation("accident") {
  1366.       X = 0;
  1367.       Y = 20;
  1368.       Hidden = TRUE;
  1369.       State = STOPPED;
  1370.     },    
  1371.     
  1372.     GuiAnimation("dash_upper") {
  1373.       AnimationID = "anim/dash/day/dash_upper.pcx";
  1374.       X = 0;
  1375.       Y = 0;
  1376.     },
  1377.     
  1378.  
  1379.     GuiAnimation("dash_lower") {
  1380.       AnimationID = "anim/dash/day/dash_lower.bmp";
  1381.       X = 0;
  1382.       Y = 236;
  1383.     },
  1384.        
  1385.     GuiButtonGroup("light_switch") {
  1386.       X = 232;
  1387.       Y = 282;
  1388.       ScriptID = Script {
  1389.         @show {
  1390.  
  1391.           resid Player;
  1392.  
  1393.           Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1394.  
  1395.           if(ResPropGetInt(Player,"truck_light") != 1) {
  1396.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"light_switch_off"));
  1397.           } else {
  1398.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"light_switch_on"));
  1399.           }
  1400.         }
  1401.         @activate { 
  1402.           resid Sound;
  1403.           resid Player;
  1404.           resid Message;
  1405.           resid restoload;
  1406.           str time_of_day;
  1407.           str weather;
  1408.           str head_light_flag;
  1409.           str rname;
  1410.           
  1411.           Message = GuiSiblingByName("message");         
  1412.           Sound = ResByName("sound/toggle.wav");
  1413.           AudioPlay(Sound);
  1414.           Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1415.  
  1416.           time_of_day = ResPropGetStr(Player,"weather_time_of_day");
  1417.           weather     = ResPropGetStr(Player,"weather_weather");
  1418.  
  1419.           if(ResPropGetInt(Player,"truck_light") != 1) {
  1420.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"light_switch_on"));          
  1421.             ResPropSetInt(Player,"truck_light",1);
  1422.             ResPropSetStr(Message, "InputText", MangleSIDToStr(10/*"Your lights are now on."*/));
  1423.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  1424.           } else {
  1425.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"light_switch_off")); 
  1426.             ResPropSetInt(Player,"truck_light",0);
  1427.             ResPropSetStr(Message, "InputText", MangleSIDToStr(11/*"Your lights are now off."*/));
  1428.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);            
  1429.           }
  1430.  
  1431.           /* ROAD */
  1432.           if ( ResPropGetInt(Player,"truck_light") == 1 ) {
  1433.             head_light_flag = "l";
  1434.           } else {
  1435.             head_light_flag = "u";
  1436.           }
  1437.  
  1438.  
  1439.           /* TODO: figure out how to not hardcode pavement */
  1440.           rname = StrFormatStr("anim/road/pavement_%s%s%s.anm", time_of_day, weather, head_light_flag);
  1441.           restoload = ResByName(rname);
  1442.           ResPropSetResID(GuiSiblingByName("road") , "AnimationID", restoload);
  1443.  
  1444.         }
  1445.       };
  1446.       
  1447.       ChildID = {
  1448.         GuiButton("light_switch_on") {
  1449.           X = 0;
  1450.           Y = 0;
  1451.           UpID = "gui/dash/light_switch/day/light_switch_on.pcx";
  1452.         },
  1453.  
  1454.         GuiButton("light_switch_off") {
  1455.           X = 0;
  1456.           Y = 0;
  1457.           UpID = "gui/dash/light_switch/day/light_switch_off.pcx";
  1458.         }
  1459.       };
  1460.     },
  1461.  
  1462.     GuiButtonGroup("wiper_switch") {
  1463.       X = 232;
  1464.       Y = 344;
  1465.       ScriptID = Script {
  1466.         @show {
  1467.           resid Player;
  1468.           Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1469.  
  1470.           if(ResPropGetInt(Player,"truck_wiper") != 1) {
  1471.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"wiper_switch_off"));
  1472.             ResPropSetInt(GuiSiblingByName("wiper"),"State",STOPPED);
  1473.             ResPropSetInt(GuiSiblingByName("wiper"),"CurrentFrame",0);
  1474.             AudioStop(ResPropGetInt(Player,"truck_wiper_sound_id"));  
  1475.           } else {
  1476.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"wiper_switch_on"));
  1477.             ResPropSetInt(GuiSiblingByName("wiper"),"State",PLAYING);
  1478.             ResPropSetInt(GuiSiblingByName("wiper"),"Loop",TRUE);   
  1479.             AudioStop(ResPropGetInt(Player,"truck_wiper_sound_id"));   
  1480.             if (StrExact(ResPropGetStr(Player,"weather_precip"),"n")) {
  1481.               ResPropSetInt(Player,"truck_wiper_sound_id",AudioPlayLooped(ResByName("sound/wiper_dry.wav")));
  1482.             } else {
  1483.               ResPropSetInt(Player,"truck_wiper_sound_id",AudioPlayLooped(ResByName("sound/wiper_wet.wav")));
  1484.             }
  1485.           }
  1486.           
  1487.           
  1488.         }
  1489.         @activate {
  1490.           resid Sound;
  1491.           resid Player;
  1492.           resid Message;
  1493.           
  1494.           Message = GuiSiblingByName("message");
  1495.           
  1496.           Sound = ResByName("sound/toggle.wav");
  1497.           AudioPlay(Sound);
  1498.  
  1499.           Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1500.           
  1501.  
  1502.           if(ResPropGetInt(Player,"truck_wiper") != 1) {
  1503.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"wiper_switch_on"));
  1504.             ResPropSetInt(Player,"truck_wiper",1);
  1505.             ResPropSetInt(GuiSiblingByName("wiper"),"State",PLAYING);
  1506.             ResPropSetInt(GuiSiblingByName("wiper"),"Loop",TRUE);
  1507.             ResPropSetStr(Message, "InputText", MangleSIDToStr(12/*"Your wipers are now on."*/));
  1508.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  1509.             if (StrExact(ResPropGetStr(Player,"weather_precip"),"n")) {
  1510.               ResPropSetInt(Player,"truck_wiper_sound_id",AudioPlayLooped(ResByName("sound/wiper_dry.wav")));
  1511.             } else {
  1512.               ResPropSetInt(Player,"truck_wiper_sound_id",AudioPlayLooped(ResByName("sound/wiper_wet.wav")));
  1513.             }
  1514.              
  1515.           } else {
  1516.             ResPropSetResID(SELF,"ActiveButtonID",GuiChildByName(SELF,"wiper_switch_off"));          
  1517.             ResPropSetInt(GuiSiblingByName("wiper"),"State",PLAYING);
  1518.             ResPropSetInt(GuiSiblingByName("wiper"),"Loop",FALSE);
  1519.             ResPropSetInt(Player,"truck_wiper",0);
  1520.             ResPropSetStr(Message, "InputText", MangleSIDToStr(13/*"Your wipers are now off."*/));
  1521.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  1522.             AudioStop(ResPropGetInt(Player,"truck_wiper_sound_id"));
  1523.           }
  1524.         }
  1525.       };
  1526.       
  1527.       ChildID = {
  1528.         GuiButton("wiper_switch_off") {
  1529.           X = 0;
  1530.           Y = 0;
  1531.           UpID = "gui/dash/wiper_switch/day/wiper_off.pcx";
  1532.         },  
  1533.  
  1534.         GuiButton("wiper_switch_on") {
  1535.           X = 0;
  1536.           Y = 0;
  1537.           UpID = "gui/dash/wiper_switch/day/wiper_on.pcx";
  1538.         }
  1539.       };
  1540.     },
  1541.  
  1542.     
  1543.     GuiAnimation("set_clock") {
  1544.       IgnoreTransparency = 1;
  1545.       X = 324;
  1546.       Y = 284;
  1547.       Width = 40;
  1548.       Height = 35;
  1549.       ScriptID = Script {
  1550.         @activate {
  1551.           resid Player;
  1552.           resid Game;
  1553.           resid Message;
  1554.           int time;
  1555.           str time_zone_real;
  1556.           int time_zone_real_offset;
  1557.           int time_zone_clock_offset;
  1558.  
  1559.           Game = ResByName("Game");
  1560.           Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1561.           Message = GuiSiblingByName("message");
  1562.  
  1563.  
  1564.             
  1565.           /* TODO:  PLAY CLOCK SET SOUND */
  1566.           time_zone_real = ResPropGetStr(Player,"time_zone_real");         
  1567.           time_zone_clock_offset = ResPropGetInt(Player,"time_zone_clock_offset");
  1568.           time_zone_real_offset = ResPropGetInt(Player,"time_zone_real_offset");
  1569.  
  1570.           if ( time_zone_real_offset == time_zone_clock_offset ) {
  1571.             ResPropSetStr(Message, "InputText", MangleSIDToStr(14/*"Your clock is already set to the proper time zone."*/));
  1572.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);    
  1573.             stop;
  1574.           }
  1575.  
  1576.           ResPropSetStr(Message, "InputText", StrFormatStr(MangleSIDToStr(15/*"Your clock is now set to %s."*/),time_zone_real));
  1577.           ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3); 
  1578.  
  1579.           ResPropSetStr(Player,"time_zone_clock",time_zone_real);
  1580.           ResPropSetInt(Player,"time_zone_clock_offset",time_zone_real_offset);
  1581.           
  1582.           
  1583.         }
  1584.       }
  1585.     },
  1586.  
  1587.     GuiTextInput("RPM_label") {
  1588.       X = 140;
  1589.       Y = 285;
  1590.       Width = 60;
  1591.       Height = 30;
  1592.       FontID = "font/digital.tf";
  1593.       InputDisabled = TRUE;
  1594.       ScriptID = Script {
  1595.         @show { 
  1596.           ResPropSetStr(SELF,"InputText",MangleSIDToStr(16/*"RPM"*/));
  1597.         }
  1598.       };
  1599.     },
  1600.  
  1601.     GuiTextInput("RPM") {
  1602.       X = 140;
  1603.       Y = 313;
  1604.       Width = 60;
  1605.       Height = 30;
  1606.       FontID = "font/digital.tf";
  1607.       InputDisabled = TRUE;     
  1608.       InputText = "";
  1609.       ScriptID = Script {
  1610.         @animate { 
  1611.           resid Player;
  1612.           int cur_speed;  
  1613.           Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1614.           ResPropAlias(Player, "truck_cur_speed","cur_speed");
  1615.           if (ResPropGetInt(Player,"truck_running") == 1) {
  1616.             ResPropSetStr(SELF,"InputText",StrFormatStr("%d",((cur_speed % 20) * 100) + 1000 + (cur_speed % 10) * 10));             
  1617.           } else {
  1618.             ResPropSetStr(SELF,"InputText","0"); 
  1619.           }
  1620.         }
  1621.       };
  1622.    },
  1623.  
  1624.    GuiTextInput("speed_label") {
  1625.      X = 60;
  1626.      Y = 285;
  1627.      Width = 60;
  1628.      Height = 30;
  1629.      FontID = "font/digital.tf";
  1630.      InputDisabled = TRUE;
  1631.      ScriptID = Script {
  1632.        @show {
  1633.          /* call the set_speed_label method in the country_specific.c4 file*/
  1634.          ResParseEvent(ResByName("common/country_specific.c4"),"@set_speed_label");
  1635.        }
  1636.      };
  1637.    },
  1638.  
  1639.    GuiTextInput("speed") {
  1640.       X = 70;
  1641.       Y = 313;
  1642.       Width = 500;
  1643.       Height = 30;
  1644.       FontID = "font/digital.tf";
  1645.       InputDisabled = TRUE;       
  1646.       InputText = "";
  1647.       ScriptID = Script {
  1648.         @animate { 
  1649.           resid Player;
  1650.           int cur_speed;
  1651.           Player = ResPropGetResID(ResByName("Game"),"game_cur_player");                        
  1652.           
  1653.           ResPropAlias(Player, "truck_cur_speed","cur_speed");
  1654.  
  1655.           if (cur_speed < ResPropGetInt(Player, "truck_speed")) {
  1656.             cur_speed = cur_speed + 8;
  1657.             cur_speed = Min(cur_speed,ResPropGetInt(Player, "truck_speed"));
  1658.           }
  1659.  
  1660.           if (cur_speed > ResPropGetInt(Player, "truck_speed")) {
  1661.             cur_speed = cur_speed - 8;
  1662.             cur_speed = Max(cur_speed,0);
  1663.           }
  1664.           
  1665.           ResPropSetStr(SELF,"InputText",StrFormatStr("%d",cur_speed));        
  1666.         }
  1667.       };
  1668.    },  
  1669.   
  1670.    GuiAnimation("clock_hour") {
  1671.      X = 276;
  1672.      Y = 288;
  1673.      ScriptID = Script {
  1674.        @draw { 
  1675.          resid Font;
  1676.          int time;
  1677.          int time_zone_clock_offset;
  1678.          str time_string;
  1679.          resid Player;
  1680.          resid Game;
  1681.          int x;
  1682.          int y;
  1683.       
  1684.          Game = ResByName("Game");
  1685.          Player = ResPropGetResID(Game,"game_cur_player");
  1686.          Font = ResByName( "font/clock.tf");
  1687.  
  1688.          time = ResPropGetInt(Player,"time_now");
  1689.          time_zone_clock_offset = ResPropGetInt(Player,"time_zone_clock_offset");
  1690.          time += (time_zone_clock_offset * 60);
  1691.          time_string = TimeGetClock12Str(time);
  1692.  
  1693.          x = ResPropGetInt(SELF,"X");
  1694.          y = ResPropGetInt(SELF,"Y");
  1695.  
  1696.          /* if the first char is 0 then dont show it */
  1697.          if (StrGetChar(time_string,0) == StrGetChar("0",0) ) {
  1698.            DrawTextStr( Font, x, y, "%s", " ");
  1699.          } else {
  1700.            DrawTextStr( Font, x, y, "%c", StrGetChar(time_string,0));
  1701.          }
  1702.  
  1703.          /* translate am or pm */
  1704.          if ( StrGetChar(time_string,9) == StrGetChar("A",0) ) {
  1705.            ResPropSetInt(GuiSiblingByName("AM"),"Hidden",FALSE);
  1706.            ResPropSetInt(GuiSiblingByName("PM"),"Hidden",TRUE);
  1707.          } else {
  1708.            ResPropSetInt(GuiSiblingByName("AM"),"Hidden",TRUE);
  1709.            ResPropSetInt(GuiSiblingByName("PM"),"Hidden",FALSE);
  1710.          }
  1711.  
  1712.          DrawTextStr( Font, x+8,  y+1, "%c",StrGetChar(time_string,1));
  1713.          DrawTextStr( Font, x+16, y+2, "%c",StrGetChar(time_string,2));
  1714.          DrawTextStr( Font, x+23, y+3, "%c",StrGetChar(time_string,3));
  1715.          DrawTextStr( Font, x+31, y+4, "%c",StrGetChar(time_string,4));
  1716.        }
  1717.      };
  1718.    },
  1719.  
  1720.   GuiAnimation("AM") {
  1721.     AnimationID = "gui/dash/clock/am.anm";
  1722.     Hidden = TRUE;
  1723.     X = 320;
  1724.     Y = 289;
  1725.   },
  1726.  
  1727.   GuiAnimation("PM") {
  1728.     AnimationID = "gui/dash/clock/pm.anm"; 
  1729.     Hidden = FALSE;
  1730.     X = 319;
  1731.     Y = 298;
  1732.   },
  1733.   
  1734.   GuiTextInput("outside_temp") {
  1735.     X = 390;
  1736.     Y = 33;
  1737.     Width = 500;
  1738.     Height = 30;
  1739.     FontID = "font/verdana_9.tf";
  1740.     InputDisabled = TRUE;
  1741.     InputText = "";
  1742.     ScriptID = Script {
  1743.       @animate {
  1744.         resid Player;
  1745.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1746.         int temperature; /* eg. 38F */
  1747.         int celcius;
  1748.         temperature = ResPropGetInt(Player,"weather_temperature");
  1749.         celcius =  temperature + 40;
  1750.         celcius *= 5;
  1751.         celcius /= 9;
  1752.         celcius -= 40;
  1753.         ResPropSetStr(SELF,"InputText",StrFormatStr("%dF %dC",temperature,celcius));
  1754.       }
  1755.     };
  1756.   },
  1757.   
  1758.   GuiTextInput("trip_meter") {
  1759.     X = 390;
  1760.     Y = 13;
  1761.     Width = 500;
  1762.     Height = 30;
  1763.     FontID = "font/verdana_9.tf";
  1764.     InputDisabled = TRUE;
  1765.     InputText = "";
  1766.     ScriptID = Script {
  1767.       @animate {
  1768.         int trip;      
  1769.         resid Player;
  1770.         resid Game;
  1771.         Game = ResByName("Game");
  1772.         Player = ResPropGetResID(Game,"game_cur_player");
  1773.         trip = ResPropGetInt(Player,"truck_trip_meter");
  1774.         ResPropSetStr(SELF,"InputText",StrFormatStr("%d",trip));
  1775.       }
  1776.     };
  1777.   },
  1778.   
  1779.   GuiAnimation("gas_gauge") {
  1780.     AnimationID = "gui/dash/gauge/gauge_.anm";   
  1781.     State = STOPPED;
  1782.     X = 57;
  1783.     Y = 346;
  1784.     Width = 340;
  1785.     Height = 360;
  1786.     
  1787.     ScriptID = Script {
  1788.       @animate {  
  1789.         resid Player;
  1790.         resid Game;
  1791.         int fuel_remaining;
  1792.         int game_tank_capacity;
  1793.         int frame_count;
  1794.         int frame;
  1795.         Game = ResByName("Game");
  1796.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1797.         frame_count = ResPropGetInt(SELF, "FrameCount");
  1798.         ResPropAlias(Player,"truck_fuel_remaining","fuel_remaining");
  1799.         ResPropAlias(Game,"game_tank_capacity","game_tank_capacity");
  1800.  
  1801.         frame = (frame_count * (fuel_remaining / 1000)) / (game_tank_capacity / 1000);
  1802.         if ( frame >= frame_count) {
  1803.           frame = frame_count - 1;
  1804.         }
  1805.         if ( frame < 0) {
  1806.           frame = 0;
  1807.         }
  1808.         ResPropSetInt(SELF,"CurrentFrame",frame);
  1809.       }
  1810.     };
  1811.   },
  1812.  
  1813.   GuiAnimation("battery_gauge") {
  1814.     AnimationID = "gui/dash/gauge/gauge_.anm";   
  1815.     State = STOPPED;
  1816.     X = 116;
  1817.     Y = 346;
  1818.     Width = 340;
  1819.     Height = 360;
  1820.    
  1821.     ScriptID = Script {
  1822.       @animate {  
  1823.         int truck_running;
  1824.         int truck_battery;
  1825.         
  1826.         resid Player;
  1827.         resid Game;
  1828.         Game = ResByName("Game");
  1829.         Player = ResPropGetResID(Game,"game_cur_player");  
  1830.         ResPropAlias(Player, "truck_battery","truck_battery");
  1831.         
  1832.         if (ResPropGetInt(Player,"truck_running") == 1) {
  1833.           
  1834.           ResPropSetInt(SELF,"CurrentFrame",5);
  1835.         
  1836.         } else {
  1837.           ResPropSetInt(SELF,"CurrentFrame",0);
  1838.         }         
  1839.       }
  1840.     };
  1841.   },
  1842.   
  1843.   GuiAnimation("temperature_gauge") {
  1844.     AnimationID = "gui/dash/gauge/gauge_.anm";   
  1845.     State = STOPPED;
  1846.     X = 176;
  1847.     Y = 346;
  1848.     Width = 340;
  1849.     Height = 360;
  1850.    
  1851.     ScriptID = Script {
  1852.       @animate {  
  1853.         int truck_running;
  1854.         int fuel_frame;
  1855.         
  1856.         resid Player;
  1857.         resid Game;
  1858.         Game = ResByName("Game");
  1859.         Player = ResPropGetResID(Game,"game_cur_player");  
  1860.         ResPropAlias(Player, "truck_running","truck_running");
  1861.         
  1862.         if (truck_running == 0) {
  1863.           ResPropSetInt(SELF,"CurrentFrame",0);
  1864.         } else {
  1865.           ResPropSetInt(SELF,"CurrentFrame",3);
  1866.         }         
  1867.       }
  1868.     };
  1869.   },
  1870.  
  1871.   GuiAnimation("ignition_switch") {
  1872.     AnimationID = "gui/dash/ignition_switch/day/ignition.anm";
  1873.     X = 307;
  1874.     Y = 383;
  1875.     State = STOPPED;
  1876.     ScriptID = Script {
  1877.     
  1878.       @show {
  1879.         /* set the switch to off or on */
  1880.         resid Player;
  1881.         resid IdleSound;
  1882.         
  1883.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  1884.         IdleSound = ResByName("sound/idle.wav");
  1885.         if(ResPropGetInt(Player,"truck_running") != 1) {
  1886.           AudioStop(ResPropGetInt(Player,"truck_engine_sound_id"));
  1887.           ResPropSetInt(SELF,"CurrentFrame",0);
  1888.         } else {
  1889.           ResPropSetInt(SELF,"CurrentFrame",8);
  1890.           AudioStop(ResPropGetInt(Player,"truck_engine_sound_id"));
  1891.           ResPropSetInt(Player,"truck_engine_sound_id", AudioPlayLooped(IdleSound));       
  1892.         }
  1893.       }
  1894.  
  1895.       @activate {
  1896.         resid Player;
  1897.         resid Game;
  1898.         resid Message;
  1899.         resid IdleSound;
  1900.         resid StartSound;
  1901.         resid StopSound;
  1902.         int truck_engine_sound_id;
  1903.         
  1904.  
  1905.         IdleSound = ResByName("sound/idle.wav");
  1906.         StartSound = ResByName("sound/truck_start.wav");
  1907.         StopSound = ResByName("sound/truck_stop.wav");
  1908.         Message = GuiSiblingByName("message");
  1909.         Game = ResByName("Game");
  1910.         Player = ResPropGetResID(Game,"game_cur_player");
  1911.               
  1912.         if (ResPropGetInt(Player,"truck_running") == 0) {
  1913.         
  1914.           /* check if we are out of gas */
  1915.           if (ResPropGetInt(Player,"truck_fuel_remaining") <= 0 ) {
  1916.             /* TODO: add cranking engine sound */
  1917.             AudioPlay(ResByName("sound/engine_trouble.wav"));
  1918.             ResPropSetStr(
  1919.               Message, 
  1920.               "InputText", 
  1921.               MangleSIDToStr(
  1922.                 17/*"You're out of fuel. Use the cellphone to call a tow truck."*/
  1923.               )
  1924.             ); 
  1925.             
  1926.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 6);
  1927.             stop;
  1928.           }
  1929.  
  1930.           /* check if the truck is broken */
  1931.           if (ResPropGetInt(Player,"truck_broken") == 1 ) {
  1932.             /* TODO: add cranking engine sound */
  1933.             AudioPlay(ResByName("sound/engine_trouble.wav"));
  1934.             ResPropSetStr(
  1935.               Message, 
  1936.               "InputText", 
  1937.               MangleSIDToStr(
  1938.                 18/*"Your truck is in need of repairs. Use the cellphone to call a tow truck."*/
  1939.               )
  1940.             ); 
  1941.             
  1942.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 6);
  1943.             stop;
  1944.           }
  1945.  
  1946.           ResPropSetInt(Player,"truck_running",1);
  1947.           ResPropSetInt(SELF,"Direction",FORWARD);
  1948.           ResPropSetInt(SELF,"Loop",FALSE);    
  1949.           ResPropSetInt(SELF,"State",PLAYING);
  1950.           
  1951.           ResPropSetStr(Message, "InputText", MangleSIDToStr(19/*"Your truck is now running."*/));
  1952.           ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);    
  1953.           
  1954.            
  1955.           ResPropSetInt(Player,"truck_engine_sound_id", AudioGroupBegin());
  1956.           AudioPlay(StartSound); 
  1957.           AudioPlayLooped(IdleSound);
  1958.           AudioGroupEnd();
  1959.  
  1960.         } else {
  1961.           if (ResPropGetInt(Player,"truck_speed") > 0) {
  1962.             ResPropSetStr(Message, "InputText", MangleSIDToStr(20/*"Your truck is still in motion! Press the brakes first!"*/));
  1963.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);  
  1964.           } else {
  1965.             AudioStop(ResPropGetInt(Player,"truck_engine_sound_id"));
  1966.            
  1967.             /* dont play the stopsound when we get a flat */
  1968.             if (ResPropGetInt(Player,"truck_tire_flat") != 1) {
  1969.               AudioPlay(StopSound);
  1970.             }
  1971.  
  1972.             /* stop the radio */
  1973.             if (ResPropGetInt(Player,"truck_radio_on_off") == 1) {
  1974.               ResParseEvent(GuiSiblingByName("radio_on_off"),"@activate");
  1975.             }
  1976.  
  1977.             ResPropSetInt(Player,"truck_running",0);
  1978.             ResPropSetInt(SELF,"Loop",FALSE);
  1979.             ResPropSetInt(SELF,"Direction",REVERSE);
  1980.             ResPropSetInt(SELF,"CurrentFrame",8);
  1981.             ResPropSetInt(SELF,"State",PLAYING);
  1982.  
  1983.             ResPropSetStr(Message, "InputText", MangleSIDToStr(21/*"Your truck is now off."*/));
  1984.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  1985.  
  1986.             ResPropSetInt(Player,"truck_speed",0);          
  1987.           }
  1988.         }
  1989.       }
  1990.     };
  1991.   },
  1992.  
  1993.   GuiAnimation("seatbelt") {
  1994.     AnimationID = "gui/dash/seatbelt/seatbelt.anm";
  1995.     X = 30;
  1996.     Y = 398;
  1997.     State = STOPPED;
  1998.     ScriptID = Script {
  1999.       @show {
  2000.         resid Player;
  2001.         resid Game;
  2002.  
  2003.        
  2004.         Game = ResByName("Game");
  2005.         Player = ResPropGetResID(Game,"game_cur_player");
  2006.         
  2007.         
  2008.         
  2009.         if ( ResPropGetInt(Player,"truck_seatbelt") == 0 ) {
  2010.           ResPropSetInt(SELF,"CurrentFrame",0);
  2011.           ResPropSetInt(SELF,"State",STOPPED);          
  2012.         } else {
  2013.           ResPropSetInt(SELF,"State",STOPPED);
  2014.           ResPropSetInt(SELF,"CurrentFrame",ResPropGetInt(SELF,"FrameCount") - 1);
  2015.         }
  2016.       }
  2017.  
  2018.       @activate {
  2019.         resid Player;
  2020.         resid Game;
  2021.         resid Message;
  2022.         resid BuckleUpSound;
  2023.         resid UnbuckleSound;
  2024.         
  2025.         Message = GuiSiblingByName("message");
  2026.         Game = ResByName("Game");
  2027.         Player = ResPropGetResID(Game,"game_cur_player");
  2028.         
  2029.         BuckleUpSound = ResByName("sound/buckle.wav");
  2030.         UnbuckleSound = ResByName("sound/unbuckle.wav");
  2031.         
  2032.         if ( ResPropGetInt(Player,"truck_seatbelt") == 0 ) {
  2033.           AudioPlay(BuckleUpSound);
  2034.           ResPropSetInt(SELF,"Direction",FORWARD);
  2035.           ResPropSetInt(SELF,"Loop",FALSE);
  2036.           ResPropSetInt(SELF,"State",PLAYING);
  2037.           ResPropSetInt(Player,"truck_seatbelt",1);
  2038.           ResPropSetStr(Message, "InputText", MangleSIDToStr(22/*"Your seat belt is now on."*/));
  2039.           ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2040.         } else {
  2041.           AudioPlay(UnbuckleSound);
  2042.           ResPropSetInt(SELF,"State",PLAYING);
  2043.           ResPropSetInt(SELF,"Loop",FALSE);
  2044.           ResPropSetInt(SELF,"Direction",REVERSE);
  2045.           ResPropSetInt(Player,"truck_seatbelt",0);
  2046.           ResPropSetStr(Message, "InputText", MangleSIDToStr(23/*"You took your seat belt off."*/));
  2047.           ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);    
  2048.         }
  2049.       }
  2050.     }    
  2051.   },
  2052.   
  2053.   GuiAnimation("brake_pedal") {
  2054.     AnimationID = "gui/dash/brake_pedal/brake.anm";  
  2055.     ActiveWhileHidden = TRUE;
  2056.     X = 140;
  2057.     Y = 398;
  2058.     State = STOPPED;
  2059.     ScriptID = Script {
  2060.  
  2061.       @activate {
  2062.         resid Player;
  2063.         resid Game;
  2064.         resid IdleSound;
  2065.         resid BrakeSound;
  2066.         int truck_engine_sound_id;
  2067.         
  2068.  
  2069.         BrakeSound = ResByName("sound/airbrake.wav");
  2070.         IdleSound = ResByName("sound/idle.wav"); 
  2071.         Game = ResByName("Game");
  2072.         Player = ResPropGetResID(Game,"game_cur_player");
  2073.  
  2074.         if (ResPropGetInt(Player,"truck_running") == 1) {
  2075.           /* set truck speed to 0 */
  2076.           if (ResPropGetInt(Player,"truck_speed") > 0) {
  2077.           
  2078.             ResPropSetInt(Player,"truck_speed", 0);
  2079.             ResPropSetInt(SELF,"Direction",FORWARD);
  2080.             ResPropSetInt(SELF,"Loop",FALSE);
  2081.             ResPropSetInt(SELF,"State",PLAYING);
  2082.             ResPropSetInt(SELF,"CurrentFrame",0);
  2083.             
  2084.             AudioStop(ResPropGetInt(Player,"truck_engine_sound_id"));
  2085.  
  2086.             ResPropSetInt(Player,"truck_engine_sound_id",AudioPlayLooped(IdleSound));
  2087.             
  2088.             if (ResPropGetInt(Player,"truck_tire_flat") != 1) {
  2089.               AudioPlay(BrakeSound);
  2090.             }
  2091.             
  2092.             /* tell the segment it should be paused, but only if the segment is running */
  2093.             if (ResPropGetInt(ResByName("dash.gl/SegmentController"),"state") == 1) {
  2094.               ResPropSetInt(ResByName("dash.gl/SegmentController"),"state",4);
  2095.             }
  2096.  
  2097.             /* tell the gas pedal it should return to resting position */
  2098.             ResPropSetInt(GuiSiblingByName("gas_pedal"),"pedal_state",0);
  2099.           }
  2100.         }
  2101.       }
  2102.     }
  2103.   },
  2104.   
  2105.   GuiGasPedal("gas_pedal") {
  2106.     AnimationID = "gui/dash/gas_pedal/gas.anm";   
  2107.     X = 210;
  2108.     Y = 398;
  2109.     State = STOPPED;
  2110.     ScriptID = Script {
  2111.       @loaded {
  2112.         ResPropSetInt(SELF,"pedal_state",0);
  2113.       }
  2114.    
  2115.       @activate {
  2116.         resid Player;
  2117.         resid Game;
  2118.         resid Message;
  2119.         resid HighIdle;
  2120.         resid VeryHighIdle;
  2121.         resid GearUp;
  2122.         resid csv_data_id;
  2123.         resid city_data_id;
  2124.         resid route_data_id;
  2125.         resid ferry_data_id;
  2126.           
  2127.         int pedal_state; /* stopped = 0, doing speed limit = 1, speeding = 2 */
  2128.         int truck_engine_sound_id;
  2129.         int city_row;
  2130.         int segment_number;
  2131.         str compass_direction;
  2132.         str ferry_name;
  2133.         str month;
  2134.         int ferry_row;
  2135.         int ferry_op_open_month;
  2136.         int ferry_op_close_month;
  2137.         int ferry_op_open_hour;
  2138.         int ferry_op_close_hour;
  2139.         int month_now;
  2140.         int hour_now;
  2141.         int time_now;
  2142.         int time_zone_real_offset;
  2143.         int ferry_cost;
  2144.         int ferry_duration;
  2145.  
  2146.         str message;
  2147.         int wait_time;
  2148.        
  2149.         csv_data_id = ResByName("CSVData");
  2150.         route_data_id = ResPropGetResID(csv_data_id, "route_id");
  2151.         city_data_id = ResPropGetResID(csv_data_id, "city_id");  
  2152.         ferry_data_id = ResPropGetResID(csv_data_id, "ferry_id");  
  2153.  
  2154.         HighIdle     = ResByName("sound/high_idle.wav");
  2155.         GearUp       = ResByName("sound/gear_up.wav");
  2156.         VeryHighIdle = ResByName("sound/very_high_idle.wav");
  2157.         Message      = GuiSiblingByName("message");
  2158.         Game         = ResByName("Game");
  2159.         Player       = ResPropGetResID(Game,"game_cur_player");
  2160.  
  2161.         ResPropAlias(SELF,"pedal_state","pedal_state");
  2162.         
  2163.         if (ResPropGetInt(Player,"truck_running") == 1) {
  2164.         
  2165.           /* if paused, unpause */
  2166.           if (  ResPropGetInt(ResByName("dash.gl/SegmentController"),"state") == 5) {
  2167.             ResPropSetInt(ResByName("dash.gl/SegmentController"),"state",6);
  2168.           } else {
  2169.             if (pedal_state == 0) {
  2170.             
  2171.               /* check our compass, see if we can go this way */
  2172.               city_row = CSVSearch(city_data_id,"name",ResPropGetStr(Player,"nav_cur_city"));
  2173.               compass_direction = ResPropGetStr(Player,"nav_compass_direction");
  2174.               segment_number = StrToInt(CSVGetStr(city_data_id,StrFormatStr("seg_%s",compass_direction),city_row));
  2175.  
  2176.               if( segment_number == -1 ) {
  2177.                 ResPropSetStr(Message, "InputText", MangleSIDToStr(24/*"You can't go that way!"*/));
  2178.                 ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2179.                 stop;
  2180.               }
  2181.  
  2182.               /* check if this route has a ferry */
  2183.               ferry_name = CSVGetStr(route_data_id,"ferry",segment_number);
  2184.               if(! strExact(ferry_name,"") ) {
  2185.                  
  2186.                 ferry_row = CSVSearch(ferry_data_id,"name",ferry_name);
  2187.                 ferry_op_open_month  = CSVGetInt(ferry_data_id,"open_month",ferry_row);
  2188.                 ferry_op_close_month = CSVGetInt(ferry_data_id,"close_month",ferry_row);
  2189.                 ferry_op_open_hour   = CSVGetInt(ferry_data_id,"open_hour",ferry_row);
  2190.                 ferry_op_close_hour  = CSVGetInt(ferry_data_id,"close_hour",ferry_row);
  2191.                 ferry_cost           = CSVGetInt(ferry_data_id,"price",ferry_row);
  2192.                 ferry_duration       = CSVGetInt(ferry_data_id,"duration",ferry_row);
  2193.                 
  2194.                 time_now = ResPropGetInt(Player,"time_now");
  2195.                 time_zone_real_offset = ResPropGetInt(Player,"time_zone_real_offset");
  2196.                 
  2197.                 hour_now  = TimeGetHour(time_now + (time_zone_real_offset * 60));
  2198.                 month_now = TimeGetMonth(time_now + (time_zone_real_offset * 60));
  2199.                 month     = TimeGetMonthStr(time_now + (time_zone_real_offset * 60));
  2200.     
  2201.                 /* check if the ferry is running in this month */
  2202.                 if ((month_now < ferry_op_open_month) || (month_now > ferry_op_close_month)) {
  2203.                   ResPropSetStr(Message, "InputText", StrFormatStr(MangleSIDToStr(25/*"The ferry on this route does not operate during the month of %s."*/),StrCapFirst(month)));
  2204.                   ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2205.                   stop;
  2206.                 }
  2207.                 
  2208.                 /* check if the ferry is running at this hour */                
  2209.                 if (hour_now < ferry_op_open_hour) {
  2210.                   message = StrFormatStr(MangleSIDToStr(26/*"The ferry on this route is not open yet. Try again in %d hour(s)."*/),( ferry_op_open_hour - hour_now));
  2211.                   ResPropSetInt(ResByName("ferry_alert.gl"),"Hidden",FALSE);
  2212.                   ResPropSetStr(ResByName("ferry_alert.gl/message"),"InputText", message);
  2213.                   CVarSetInt("ferry_wait_time",(((ferry_op_open_hour - hour_now) * 60 ) * 60));
  2214.  
  2215.                   stop;
  2216.                 }
  2217.                
  2218.                 /* check if the ferry is running at this hour */
  2219.                 if (hour_now > ferry_op_close_hour) {
  2220.                   message = StrFormatStr(MangleSIDToStr(27/*"The ferry on this route is closed. Try again in %d hour(s)."*/),((24-hour_now) + ferry_op_open_hour));
  2221.                   ResPropSetInt(ResByName("ferry_alert.gl"),"Hidden",FALSE);
  2222.                   ResPropSetStr(ResByName("ferry_alert.gl/message"),"InputText", message);
  2223.                   CVarSetInt("ferry_wait_time", ((((24 - hour_now) + ferry_op_open_hour) * 60 ) * 60));
  2224.                   stop;
  2225.                 }
  2226.                 
  2227.                
  2228.                 /* charge the user the price of the ferry */
  2229.                 ResPropSetInt(Player,"expense_spent_on_fuel",ResPropGetInt(Player,"expense_spent_on_fuel") + ferry_cost * 100);
  2230.                 
  2231.                 /* add the time it takes to go on this ferry */
  2232.                 ResPropSetInt(Player, "time_now", ResPropGetInt( Player, "time_now" ) + ferry_duration);
  2233.                
  2234.                 ResPropSetStr(Message, "InputText", StrFormatStr(MangleSIDToStr(28/*"The %s ferry will take %d minutes and will cost $%d dollars."*/),ferry_name,(ferry_duration / 60),ferry_cost));
  2235.                 ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2236.  
  2237.               }
  2238.               
  2239.               ResPropSetInt(ResByName("dash.gl/SegmentController"),"segment_number",segment_number);
  2240.               ResPropSetInt(ResByName("dash.gl/SegmentController"),"state",3);
  2241.             }
  2242.           }
  2243.  
  2244.           if (pedal_state == 2) {
  2245.             pedal_state = 1;
  2246.  
  2247.             AudioStop(ResPropGetInt(Player,"truck_engine_sound_id"));
  2248.             ResPropSetInt(Player,"truck_engine_sound_id",AudioPlayLooped(HighIdle));
  2249.             ResPropSetInt(Player, "truck_speeding", 0);
  2250.                            
  2251.           } else {
  2252.             if (pedal_state == 1) {
  2253.               pedal_state = 2;
  2254.            
  2255.               AudioStop(ResPropGetInt(Player,"truck_engine_sound_id"));
  2256.  
  2257.               ResPropSetInt(Player,"truck_engine_sound_id",AudioPlayLooped(VeryHighIdle));
  2258.               ResPropSetStr(Message, "InputText", MangleSIDToStr(29/*"Maybe you should slow down. You're speeding."*/));
  2259.               ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2260.               ResPropSetInt(Player, "truck_speeding", 1);
  2261.             }
  2262.           }
  2263.           
  2264.           if (pedal_state == 0) {
  2265.  
  2266.             AudioStop(ResPropGetInt(Player,"truck_engine_sound_id"));
  2267.  
  2268.             ResPropSetInt(Player,"truck_engine_sound_id",AudioPlayLooped(HighIdle));
  2269.             AudioPlay(GearUp);
  2270.             /* set to current segment speed limit */
  2271.             pedal_state = 1;
  2272.             ResPropSetInt(Player, "truck_speeding", 0);
  2273.             
  2274.             ResPropSetInt(GuiSiblingByName("in_dash"),"Hidden",TRUE);     
  2275.           }
  2276.  
  2277.         } else {
  2278.           ResPropSetStr(Message, "InputText", MangleSIDToStr(30/*"Your truck is not running. Turn it on first!"*/));
  2279.           ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2280.           ResPropSetInt(Player, "truck_speeding", 0);
  2281.         } 
  2282.       }
  2283.       @animate {
  2284.         resid Player;
  2285.         resid Game;
  2286.         resid Message;
  2287.         resid route_data_id;
  2288.         resid csv_data_id;
  2289.         int segment_number;
  2290.         int pedal_state;
  2291.         int CurrentFrame;
  2292.         
  2293.         ResPropAlias(SELF,"CurrentFrame","CurrentFrame");
  2294.         ResPropAlias(SELF,"pedal_state","pedal_state");
  2295.         Message = GuiSiblingByName("message");
  2296.         Game = ResByName("Game");
  2297.         Player = ResPropGetResID(Game,"game_cur_player");
  2298.         csv_data_id = ResByName("CSVData");
  2299.         route_data_id = ResPropGetResID(csv_data_id, "route_id");
  2300.  
  2301.         if (ResPropGetInt(Player,"truck_running") == 1) {
  2302.         
  2303.         
  2304.           if (pedal_state == 0) {
  2305.             if (CurrentFrame > 0) {
  2306.               ResPropSetInt(SELF,"State",PLAYING);
  2307.               ResPropSetInt(SELF,"Loop",FALSE);
  2308.               ResPropSetInt(SELF,"Direction",REVERSE);
  2309.             } else {
  2310.               ResPropSetInt(SELF,"State",STOPPED);
  2311.             }
  2312.           }
  2313.           
  2314.           /* if we stepped on the gas */
  2315.           if (pedal_state == 1) {
  2316.             if (CurrentFrame < 7) {
  2317.               ResPropSetInt(SELF,"State",PLAYING);
  2318.               ResPropSetInt(SELF,"Loop",FALSE);
  2319.               ResPropSetInt(SELF,"Direction",FORWARD);
  2320.             }
  2321.             if (CurrentFrame > 7) {
  2322.               ResPropSetInt(SELF,"State",PLAYING);
  2323.               ResPropSetInt(SELF,"Loop",FALSE);
  2324.               ResPropSetInt(SELF,"Direction",REVERSE);
  2325.             }
  2326.             if (CurrentFrame == 7) {
  2327.               ResPropSetInt(SELF,"State",STOPPED);
  2328.             }
  2329.             
  2330.             if (ResPropGetInt(Player,"truck_speeding") == 1) {
  2331.               segment_number = ResPropGetInt(GuiSiblingByName("SegmentController"),"segment_number");
  2332.               ResPropSetInt(Player, "truck_speed", StrToInt(CSVGetStr(route_data_id,"speed_limit",segment_number)) + 20);
  2333.             } else {
  2334.               segment_number = ResPropGetInt(GuiSiblingByName("SegmentController"),"segment_number");
  2335.               ResPropSetInt(Player, "truck_speed", StrToInt(CSVGetStr(route_data_id,"speed_limit",segment_number)));
  2336.             }
  2337.           }
  2338.           
  2339.           if (pedal_state == 2) {
  2340.             if (CurrentFrame < 10) {
  2341.               ResPropSetInt(SELF,"State",PLAYING);
  2342.               ResPropSetInt(SELF,"Loop",FALSE);
  2343.               ResPropSetInt(SELF,"Direction",FORWARD);
  2344.             } else {
  2345.               ResPropSetInt(SELF,"State",STOPPED);
  2346.               
  2347.               if (ResPropGetInt(Player,"truck_speeding") == 1) {
  2348.                 segment_number = ResPropGetInt(GuiSiblingByName("SegmentController"),"segment_number");
  2349.                 ResPropSetInt(Player, "truck_speed", StrToInt(CSVGetStr(route_data_id,"speed_limit",segment_number)) + 20);
  2350.               } else {
  2351.                 segment_number = ResPropGetInt(GuiSiblingByName("SegmentController"),"segment_number");
  2352.                 ResPropSetInt(Player, "truck_speed", StrToInt(CSVGetStr(route_data_id,"speed_limit",segment_number)));
  2353.               }              
  2354.             }
  2355.           }
  2356.         } else {
  2357.           ResPropSetInt(SELF,"CurrentFrame",0);
  2358.           ResPropSetInt(SELF,"State",STOPPED);
  2359.         }
  2360.         
  2361.       }
  2362.     };
  2363.   },
  2364.     
  2365.   GuiMessageText("message") {
  2366.     X = 45;
  2367.     Y = 238;
  2368.     Width = 500;
  2369.     Height = 50;
  2370.     FontID = "font/verdana_9.tf";
  2371.     InputDisabled = TRUE;       
  2372.     InputText = "";
  2373.     WordWrap = TRUE;    
  2374.     timeout = 0;
  2375.     ScriptID = Script {
  2376.       @animate { 
  2377.         int timeout;
  2378.         int time;
  2379.         int time_zone_clock_offset;
  2380.         str time_string;
  2381.         str last_message;
  2382.         resid Player;
  2383.         resid Game;
  2384.         Game = ResByName("Game");
  2385.         Player = ResPropGetResID(Game,"game_cur_player"); 
  2386.         ResPropAlias(Player,"player_last_message","last_message");
  2387.         ResPropAlias(SELF,"timeout","timeout");
  2388.         
  2389.         
  2390.         if (! StrExact(ResPropGetStr(SELF,"InputText"), last_message)) {
  2391.           if (! StrExact(ResPropGetStr(SELF,"InputText"),"")) {
  2392.             
  2393.             last_message = ResPropGetStr(SELF,"InputText");
  2394.             
  2395.             time = ResPropGetInt(Player,"time_now");
  2396.             time_zone_clock_offset = ResPropGetInt(Player,"time_zone_clock_offset");
  2397.             time += (time_zone_clock_offset * 60);
  2398.  
  2399.             time_string = StrFormatStr("%s %d, %s -", StrCapFirst(TimeGetMonthStr(time)), TimeGetDay(time), TimeGetClock24Str(time) );        
  2400.  
  2401.             if (ResPropGetInt(Player,"player_destination_arrived") != 1) {
  2402.               StrListAppend(
  2403.                 ResPropGetResID(Player, "travel_log"),
  2404.                 StrFormatStr(
  2405.                   "%s %s",
  2406.                   time_string,
  2407.                   ResPropGetStr(
  2408.                     SELF,
  2409.                     "InputText"
  2410.                   )
  2411.                 )
  2412.               );
  2413.             }
  2414.  
  2415.           }
  2416.         }
  2417.  
  2418.        
  2419.         if (timeout < 0) {
  2420.           ResPropSetStr(SELF,"InputText","");
  2421.         } else {
  2422.           timeout -= 1;
  2423.         }
  2424.       }
  2425.     };
  2426.   },
  2427.   
  2428.   
  2429.   GuiTileMap("GPS") {
  2430.     X = 464;
  2431.     Y = 273;
  2432.     TileMapID = "map.tm";
  2433.     Width = 170;
  2434.     Height = 125;
  2435.     ScrollX = 0;
  2436.     ScrollY = 0;
  2437.     ScriptID = Script {
  2438.       @activate {
  2439.          resid mc;
  2440.          
  2441.          ResParseEvent(GuiSiblingByName("brake_pedal"),"@activate");
  2442.          mc = ResByName("laptop.gl/laptop_controller");
  2443.          ResPropSetInt(mc,"hide_all", 0);
  2444.          ResPropSetInt(ResByName("laptop.gl"),"Hidden",FALSE);
  2445.          Mark("laptop");
  2446.       }
  2447.     }
  2448.   },
  2449.  
  2450.   GuiAnimation("radio_on_off") {
  2451.     AnimationID = "gui/dash/radio/day/radio_left.pcx";   
  2452.     X = 269;
  2453.     Y = 312;
  2454.     State = STOPPED;
  2455.     ScriptID = Script {
  2456.       @activate {
  2457.         resid Player;
  2458.         resid Message;
  2459.         resid Game;
  2460.         int truck_radio_sound_id;
  2461.        
  2462.         Message = GuiSiblingByName("message");
  2463.         Game = ResByName("Game");
  2464.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2465.         ResPropAlias(Player,"truck_radio_sound_id","truck_radio_sound_id");
  2466.         
  2467.         if (ResPropGetInt(Player,"truck_radio_on_off") == 1) {
  2468.           AudioStop(truck_radio_sound_id);
  2469.           ResPropSetInt(Player,"truck_radio_on_off",0);
  2470.         } else {
  2471.           if (ResPropGetInt(Player,"truck_running") == 1) {
  2472.             ResPropSetInt(Player,"truck_radio_on_off",1);
  2473.             ResPropSetInt(Player,"truck_radio_freq",Random(875,1080));
  2474.             ResParseEvent(GuiSiblingByName("radio_seek"),"@activate");
  2475.           } else {
  2476.             /* tell them to turn on the radio first */
  2477.             ResPropSetStr(Message, "InputText", MangleSIDToStr(31/*"The truck must be running for the radio to work."*/));
  2478.             ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2479.           }
  2480.         }
  2481.       }
  2482.     };
  2483.   },
  2484.   GuiAnimation("radio_display") {
  2485.     X = 293;
  2486.     Y = 327;
  2487.     State = STOPPED;
  2488.     ScriptID = Script {
  2489.       @draw {
  2490.         resid Player;
  2491.         resid Game;
  2492.         resid Font;
  2493.  
  2494.         str freq_str;
  2495.         int truck_radio_freq;
  2496.         int truck_radio_freq_cur;
  2497.         
  2498.         Font = ResByName( "font/radio.tf");
  2499.         Game = ResByName("Game");
  2500.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2501.         
  2502.         ResPropAlias(Player,"truck_radio_freq","truck_radio_freq");
  2503.         ResPropAlias(Player,"truck_radio_freq_cur","truck_radio_freq_cur");  
  2504.  
  2505.         if (ResPropGetInt(Player,"truck_radio_on_off") != 1) {
  2506.          stop;
  2507.         }
  2508.  
  2509.         if (truck_radio_freq_cur < truck_radio_freq) {
  2510.           truck_radio_freq_cur += 30;
  2511.         }
  2512.         
  2513.         if (truck_radio_freq_cur > truck_radio_freq) {
  2514.           truck_radio_freq_cur = truck_radio_freq_cur - 30;
  2515.         }        
  2516.                 
  2517.         freq_str = StrFormatStr("%d",truck_radio_freq_cur);
  2518.         DrawTextStr( Font, ResPropGetInt(SELF,"X")+8, ResPropGetInt(SELF,"Y")+1, "%c",  StrGetChar(freq_str,0));
  2519.         DrawTextStr( Font, ResPropGetInt(SELF,"X")+16, ResPropGetInt(SELF,"Y")+2, "%c", StrGetChar(freq_str,1));
  2520.         DrawTextStr( Font, ResPropGetInt(SELF,"X")+23, ResPropGetInt(SELF,"Y")+3, "%c", StrGetChar(freq_str,2));
  2521.         DrawTextStr( Font, ResPropGetInt(SELF,"X")+31, ResPropGetInt(SELF,"Y")+4, "%c", StrGetChar(freq_str,3));
  2522.       }
  2523.  
  2524.     };
  2525.   },
  2526.   GuiAnimation("radio_seek") {
  2527.     AnimationID = "gui/dash/radio/day/radio_right.pcx";   
  2528.     X = 342;
  2529.     Y = 317;
  2530.     State = STOPPED;
  2531.     ScriptID = Script {
  2532.       @activate {
  2533.         resid Player;
  2534.         resid Game;
  2535.         resid Message;
  2536.  
  2537.         int truck_radio_freq;
  2538.         int truck_radio_freq_cur;
  2539.         int truck_radio_on_off;
  2540.         int truck_radio_sound_id;
  2541.         int cur_song;
  2542.  
  2543.         Message = GuiSiblingByName("message");
  2544.         Game = ResByName("Game");
  2545.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2546.         
  2547.         ResPropAlias(Player,"truck_radio_on_off","truck_radio_on_off");
  2548.         ResPropAlias(Player,"truck_radio_freq","truck_radio_freq");
  2549.         ResPropAlias(Player,"truck_radio_freq_cur","truck_radio_freq_cur");
  2550.         ResPropAlias(Player,"truck_radio_sound_id","truck_radio_sound_id");           
  2551.         
  2552.         if (truck_radio_on_off == 1) {
  2553.           truck_radio_freq_cur = truck_radio_freq;
  2554.           if (  ((truck_radio_freq + 100) > 1080)  ||   truck_radio_freq < 875 ){
  2555.             truck_radio_freq = 875;
  2556.           } else {
  2557.             truck_radio_freq += Random(3,9);
  2558.           }
  2559.           
  2560.  
  2561.           AudioStop(truck_radio_sound_id);
  2562.           truck_radio_sound_id = AudioGroupBegin();
  2563.  
  2564.           cur_song = Random(1,5);
  2565.           AudioPlay(ResByName(StrFormatStr("sound/radio/tuning/tuning_%d.wav",cur_song)));
  2566.           cur_song = Random(1,10);
  2567.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));
  2568.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));          
  2569.           cur_song = Random(1,10);          
  2570.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));
  2571.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));          
  2572.           cur_song = Random(1,10);
  2573.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));
  2574.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));          
  2575.           cur_song = Random(1,10);
  2576.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));
  2577.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));
  2578.           cur_song = Random(1,10);
  2579.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));
  2580.           AudioPlay(ResByName(StrFormatStr("sound/radio/radio_%d.wav",cur_song)));
  2581.           cur_song = Random(1,2);
  2582.           AudioPlayLooped(ResByName(StrFormatStr("sound/radio/static/static_%d.wav",cur_song)));
  2583.           AudioGroupEnd();
  2584.           
  2585.         } else {
  2586.           /* tell them to turn on the radio first */
  2587.           ResPropSetStr(Message, "InputText", MangleSIDToStr(32/*"Your radio is not on. Turn it on first!"*/));
  2588.           ResPropSetInt(Message, "timeout", CVarGetInt("framerate") * 3);
  2589.         }
  2590.    
  2591.       }
  2592.     };
  2593.   },
  2594.  
  2595.   GuiAnimation("Compass") {
  2596.     AnimationID = "gui/dash/compass/compass.anm"; 
  2597.     State = STOPPED;
  2598.     X = 321;
  2599.     Y = 17;
  2600.     ScriptID = Script {
  2601.       @animate { 
  2602.         str nav_compass_direction;
  2603.         int frame;
  2604.         resid Player;
  2605.         resid Game;
  2606.         Game = ResByName("Game");
  2607.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2608.         ResPropAlias(Player,"nav_compass_direction","nav_compass_direction");
  2609.         
  2610.         /*
  2611.           Compass Direction:
  2612.           N  = North
  2613.           NE = North East
  2614.           E  = East
  2615.           SE = South East
  2616.           S  = South
  2617.           SW = South West
  2618.           W  = West
  2619.           NW = North West  
  2620.         */
  2621.    
  2622.         if (StrExact(nav_compass_direction,"N"))  { frame = 0; }
  2623.         if (StrExact(nav_compass_direction,"NE")) { frame = 1; }
  2624.         if (StrExact(nav_compass_direction,"E"))  { frame = 2; }
  2625.         if (StrExact(nav_compass_direction,"SE")) { frame = 3; }
  2626.         if (StrExact(nav_compass_direction,"S"))  { frame = 4; }
  2627.         if (StrExact(nav_compass_direction,"SW")) { frame = 5; }
  2628.         if (StrExact(nav_compass_direction,"W"))  { frame = 6; }
  2629.         if (StrExact(nav_compass_direction,"NW")) { frame = 7; }
  2630.         ResPropSetInt(SELF,"CurrentFrame",frame);
  2631.       }
  2632.     }
  2633.   },
  2634.  
  2635.   GuiAnimation("N") {
  2636.     AnimationID = "gui/dash/compass/invisible.pcx";
  2637.     IgnoreTransparency = 1;
  2638.     X = 346;
  2639.     Y = 18;
  2640.     ScriptID = Script {
  2641.       @activate {
  2642.         str nav_compass_direction;
  2643.         resid Player;
  2644.         resid Game;
  2645.         Game = ResByName("Game");
  2646.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2647.         ResPropSetStr(Player,"nav_compass_direction","N");
  2648.       }
  2649.     }
  2650.   },
  2651.  
  2652.   GuiAnimation("NE") {
  2653.     AnimationID = "gui/dash/compass/invisible.pcx";
  2654.     IgnoreTransparency = 1;
  2655.     X = 364;
  2656.     Y = 21;
  2657.     ScriptID = Script {
  2658.       @activate {
  2659.         str nav_compass_direction;
  2660.         resid Player;
  2661.         resid Game;
  2662.         Game = ResByName("Game");
  2663.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2664.         ResPropSetStr(Player,"nav_compass_direction","NE");
  2665.       }
  2666.     }
  2667.   },
  2668.  
  2669.   GuiAnimation("E") {
  2670.     AnimationID = "gui/dash/compass/invisible.pcx";
  2671.     IgnoreTransparency = 1;
  2672.     X = 368;
  2673.     Y = 38;
  2674.     ScriptID = Script {
  2675.       @activate {
  2676.         str nav_compass_direction;
  2677.         resid Player;
  2678.         resid Game;
  2679.         Game = ResByName("Game");
  2680.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2681.         ResPropSetStr(Player,"nav_compass_direction","E");
  2682.       }
  2683.     }
  2684.   },
  2685.  
  2686.   GuiAnimation("SE") {
  2687.     AnimationID = "gui/dash/compass/invisible.pcx";
  2688.     IgnoreTransparency = 1;
  2689.     X = 362;
  2690.     Y = 56;
  2691.     ScriptID = Script {
  2692.       @activate {
  2693.         str nav_compass_direction;
  2694.         resid Player;
  2695.         resid Game;
  2696.         Game = ResByName("Game");
  2697.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2698.         ResPropSetStr(Player,"nav_compass_direction","SE");
  2699.       }
  2700.     }
  2701.   },  
  2702.  
  2703.   GuiAnimation("S") {
  2704.     AnimationID = "gui/dash/compass/invisible.pcx";
  2705.     IgnoreTransparency = 1;
  2706.     X = 345;
  2707.     Y = 61;
  2708.     ScriptID = Script {
  2709.       @activate {
  2710.         str nav_compass_direction;
  2711.         resid Player;
  2712.         resid Game;
  2713.         Game = ResByName("Game");
  2714.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2715.         ResPropSetStr(Player,"nav_compass_direction","S");
  2716.       }
  2717.     }
  2718.   },  
  2719.  
  2720.   GuiAnimation("SW") {
  2721.     AnimationID = "gui/dash/compass/invisible.pcx";
  2722.     IgnoreTransparency = 1;
  2723.     X = 326;
  2724.     Y = 56;
  2725.     ScriptID = Script {
  2726.       @activate {
  2727.         str nav_compass_direction;
  2728.         resid Player;
  2729.         resid Game;
  2730.         Game = ResByName("Game");
  2731.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2732.         ResPropSetStr(Player,"nav_compass_direction","SW");
  2733.       }
  2734.     }
  2735.   },  
  2736.  
  2737.   GuiAnimation("W") {
  2738.     AnimationID = "gui/dash/compass/invisible.pcx";
  2739.     IgnoreTransparency = 1;
  2740.     X = 323;
  2741.     Y = 38;
  2742.     ScriptID = Script {
  2743.       @activate {
  2744.         str nav_compass_direction;
  2745.         resid Player;
  2746.         resid Game;
  2747.         Game = ResByName("Game");
  2748.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2749.         ResPropSetStr(Player,"nav_compass_direction","W");
  2750.       }
  2751.     }
  2752.   },
  2753.   
  2754.   GuiAnimation("NW") {
  2755.     AnimationID = "gui/dash/compass/invisible.pcx";
  2756.     IgnoreTransparency = 1;
  2757.     X = 328;
  2758.     Y = 23;
  2759.     ScriptID = Script {
  2760.       @activate {
  2761.         str nav_compass_direction;
  2762.         resid Player;
  2763.         resid Game;
  2764.         Game = ResByName("Game");
  2765.         Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2766.         ResPropSetStr(Player,"nav_compass_direction","NW");
  2767.       }
  2768.     }
  2769.   },
  2770.   GuiAnimation("cell_phone") {
  2771.    /* AnimationID = "gui/dash/cell_phone/open_invisible.pcx";*/
  2772.    IgnoreTransparency = TRUE;
  2773.     X = 406;
  2774.     Y = 364;
  2775.     Width = 50;
  2776.     Height = 107;      
  2777.     ScriptID = Script {
  2778.       @activate {
  2779.         ResPropSetInt(ResByNAme("cell_phone.gl"),"Hidden",FALSE);
  2780.       }
  2781.     };
  2782.   },
  2783.  
  2784.  
  2785.    GuiAnimation("full_screen_sky") {
  2786.      Hidden = TRUE;
  2787.      X = 0;
  2788.      Y = 0;
  2789.    },
  2790.   
  2791.    GuiFullscreenPicture("full_screen") {
  2792.      Hidden = TRUE;
  2793.      X = 0;
  2794.      Y = 0;
  2795.  
  2796.      
  2797.      ScriptID = Script {
  2798.  
  2799.        @show {
  2800.          resid Player;
  2801.          resid Sky;
  2802.          resid commodity_data_id;
  2803.          str ext;
  2804.          str season;
  2805.          str time_of_day;
  2806.          str precip;
  2807.          str picture;
  2808.          str fs_picture;
  2809.          str id_picture;
  2810.          int nav_picture_no_dash_flag;
  2811.          int com_load;
  2812.          
  2813.  
  2814.          Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2815.          ResPropAlias(Player,"weather_season","season");
  2816.          ResPropAlias(Player,"weather_time_of_day","time_of_day");
  2817.          ResPropAlias(Player,"weather_precip","precip");
  2818.          ResPropAlias(Player,"nav_picture","picture");         
  2819.          ResPropAlias(Player,"nav_picture_no_dash_flag","nav_picture_no_dash_flag");  
  2820.           
  2821.          /* if the truck is running shut it down */
  2822.          if (ResPropGetInt(Player,"truck_running") == 1) {
  2823.            /* switch the ignition */
  2824.            ResParseEvent(GuiSiblingByName("brake_pedal"),"@activate");         
  2825.            ResParseEvent(ResByName("dash.gl/ignition_switch"),"@activate");
  2826.          }
  2827.   
  2828.  
  2829.  
  2830.          /* if the picture to show is the victory screen ext is jpg */
  2831.          /* if the picture is found in the commodity table, extension is populated by the table */
  2832.          /* pcx is the default extension */
  2833.  
  2834.          com_load = 0;
  2835.          if (StrExact(picture,"victory")) {
  2836.            ext = "jpg";
  2837.            ResPropSetStr(GuiSiblingByName("congrats_text"),"InputText", StrFormatStr(MangleSIDToStr(33/*"Congratulations, %s! You have completed your assignment!"*/),ResPropGetStr(Player,"player_name")));              
  2838.            ResPropSetInt(GuiSiblingByName("congrats_text"),"Hidden",FALSE);
  2839.          } else {
  2840.            commodity_data_id = ResPropGetResID(ResByName("CSVData"), "commodity_id");
  2841.            ext = CSVGetStr(commodity_data_id,"extension", CSVSearch(commodity_data_id, "animation",  picture ));
  2842.            if (StrExact(ext,"")) {
  2843.              ext = "pcx"; 
  2844.            } else {
  2845.              com_load = 1;
  2846.            }
  2847.            
  2848.          }
  2849.          
  2850.          if ( (CVarGetInt("hide_weather_during_load") != 1) && (com_load != 1) ) {
  2851.  
  2852.            /* show the rain if raining */
  2853.            if (StrExact(precip,"r")) {
  2854.              ResPropSetInt(GuiSiblingByName("rain_fullscreen"),"Hidden", FALSE );
  2855.            }
  2856.            
  2857.            /* show the snow if snowing */
  2858.            if (StrExact(precip,"s")) {
  2859.              ResPropSetInt(GuiSiblingByName("snow_fullscreen"),"Hidden", FALSE );
  2860.            }
  2861.            
  2862.          }
  2863.  
  2864.  
  2865.          fs_picture = StrFormatStr("anim/%s/%s_fs_%s%s.%s",picture,picture,time_of_day,season,ext);
  2866.          id_picture = StrFormatStr("anim/%s/%s_id_%s%s.%s",picture,picture,time_of_day,season,ext);
  2867.          
  2868.          /* set this animation to the fs_picture */
  2869.          ResPropSetResID(SELF,"AnimationID",ResByName(fs_picture));
  2870.  
  2871.          
  2872.          /* set the fullscreen sky */
  2873.          /* TODO: need a dusk setting too */
  2874.          if (StrExact(time_of_day,"d")) {
  2875.            if (StrExact(precip,"n")) {
  2876.              if (ResPropGetInt(Player, "weather_sky_clarity") < 15) {
  2877.                Sky = ResByName("anim/sky/overcast_fs.jpg");
  2878.              } else {
  2879.                if (ResPropGetInt(Player, "weather_sky_clarity") < 30) {
  2880.                  Sky = ResByName("anim/sky/light_clouds_fs.jpg");
  2881.                } else {
  2882.                  Sky = ResByName("anim/sky/blue_fs.jpg");
  2883.                }
  2884.              }
  2885.            }
  2886.            if (StrExact(precip,"s")) {
  2887.              Sky = ResByName("anim/sky/stormy_fs.jpg");
  2888.            }
  2889.            if (StrExact(precip,"r")) {
  2890.              Sky = ResByName("anim/sky/stormy_fs.jpg");
  2891.            }       
  2892.          } else {
  2893.            if (StrExact(precip,"n")) {
  2894.              Sky = ResByName("anim/sky/stars_fs.jpg");
  2895.            }
  2896.            if (StrExact(precip,"s")) {
  2897.              Sky = ResByName("anim/sky/stars_fs.jpg");
  2898.            }
  2899.            if (StrExact(precip,"r")) {
  2900.              Sky = ResByName("anim/sky/stars_fs.jpg");
  2901.            }    
  2902.          }
  2903.          
  2904.          ResPropSetResID(GuiSiblingByName("full_screen_sky"),"AnimationID",Sky);
  2905.          ResPropSetInt(GuiSiblingByName("full_screen_sky"),"Hidden",FALSE);
  2906.          
  2907.          /* set the animation of the in dash picture if there is one */
  2908.          if ( nav_picture_no_dash_flag == 1 ) {
  2909.            nav_picture_no_dash_flag = 0;
  2910.          } else {
  2911.            /* show in dash version */
  2912.            ResPropSetResID(GuiSiblingByName("in_dash"),"AnimationID",ResByName(id_picture));
  2913.            ResPropSetInt(GuiSiblingByName("in_dash"),"Hidden",FALSE);   
  2914.          }
  2915.  
  2916.  
  2917.          /* hide tabs */
  2918.          ResParseEvent(ResByName("common/hide_show.c4"),"@HIDE_TABS");
  2919.          ResPropSetInt(SELF,"timeout",80);           
  2920.          GuiToFront(SELF);
  2921.          GuiToFront(GuiSiblingByName("snow_fullscreen"));
  2922.          GuiToFront(GuiSiblingByName("rain_fullscreen"));
  2923.          GuiToFront(GuiSiblingByName("congrats_text"));    
  2924.        }
  2925.  
  2926.        @animate {
  2927.          int timeout;
  2928.          str sound;
  2929.          resid FSSound;
  2930.          resid Player;
  2931.                   
  2932.         
  2933.          Player = ResPropGetResID(ResByName("Game"),"game_cur_player");
  2934.          ResPropAlias(Player,"nav_sound","sound");
  2935.          ResPropAlias(SELF,"timeout","timeout");
  2936.          
  2937.          
  2938.          if (timeout > 0) {
  2939.            if (timeout == 60) {
  2940.              if (! StrExact(sound,"")) {
  2941.                FSSound = ResByName(StrFormatStr("sound/%s.wav",sound));
  2942.                AudioPlay(FSSound);
  2943.                sound = "";
  2944.              } else {
  2945.                /* LOG(LOG_DEBUG,"WARNING, NO SOUND FOR THIS FULLSCREEN THING\n"); */
  2946.              }
  2947.            }
  2948.            timeout -= 1;
  2949.          } else {
  2950.  
  2951.            /* set night day */
  2952.            ResParseEvent(ResByName("common/set_night_day.c4"),"@set_night_day");
  2953.     
  2954.            ResParseEvent(ResByName("common/hide_show.c4"),"@SHOW_TABS");
  2955.            ResPropSetInt(GuiSiblingByName("snow_fullscreen"),"Hidden", TRUE );
  2956.            ResPropSetInt(GuiSiblingByName("rain_fullscreen"),"Hidden", TRUE );
  2957.  
  2958.            ResPropSetInt(SELF,"Hidden",TRUE);
  2959.            ResPropSetInt(GuiSiblingByName("full_screen_sky"),"Hidden",TRUE);
  2960.            ResPropSetInt(GuiSiblingByName("congrats_text"),"Hidden",TRUE);
  2961.  
  2962.            if (ResPropGetInt(Player,"player_destination_arrived") == 0) {
  2963.              /* check if we have arrived at the destination city */
  2964.              ResParseEvent(ResByName("common/destination_arrived.c4"),"@destination_arrived");
  2965.              if (ResPropGetInt(Player,"player_destination_arrived") == 1) {
  2966.                stop;
  2967.              }
  2968.            }       
  2969.  
  2970.            /* call switch player */
  2971.            if (ResPropGetInt(Player,"nav_switch_player") == 1) {
  2972.              /* Log(LOG_DEBUG,"SWITCH PLAYERS DUE TO COM LOAD\n"); */
  2973.              ResPropSetInt(Player,"nav_switch_player",0);
  2974.              ResParseEvent(ResByName("common/switch_player.c4"),"@switch_player");             
  2975.              stop;
  2976.            }
  2977.            
  2978.  
  2979.  
  2980.          }
  2981.        }
  2982.      }
  2983.    },
  2984.     
  2985.     GuiTextInput("congrats_text") {
  2986.       Y = 110;
  2987.       X = 67;
  2988.       Hidden = TRUE;
  2989.       InputDisabled = TRUE;
  2990.       InputHorizontalAlign = CENTER;
  2991.       WordWrap = TRUE;
  2992.       Width = 504;
  2993.       Height = 60;
  2994.       FontID = "font/verdana_black_bold_14.tf";    
  2995.     },
  2996.  
  2997.    GuiParticleSystem("rain_fullscreen") {
  2998.      Hidden = TRUE;
  2999.      X = 0;
  3000.      Y = 0;
  3001.      Width = 640;
  3002.      Height = 480;
  3003.      ParticleSystemID = ParticleSystem("rf") {
  3004.        EmitterType = LINE_HORIZONTAL;
  3005.        EmitterX = 0;
  3006.        EmitterY = -50;
  3007.        EmitterWidth = 640;
  3008.        EmitterHeight = 480;
  3009.        AnimationID = "anim/particle/rain.pcx";
  3010.        BirthRate = 3;
  3011.        BirthRateVariation = 0;
  3012.        VelMX = 2000;
  3013.        VelMXVariation = 1000;
  3014.        VelMY = 26000;
  3015.        VelMYVariation = 3000;
  3016.        Life = 22;
  3017.        LifeVariation = 0;
  3018.        LeadTime = 0;
  3019.      }
  3020.    },    
  3021.     
  3022.    GuiParticleSystem("snow_fullscreen") {
  3023.      Hidden = TRUE;
  3024.      X = -200;
  3025.      Y = 0;
  3026.      Width = 840;
  3027.      Height = 480;
  3028.      ParticleSystemID = ParticleSystem("sf") {
  3029.        EmitterType = LINE_HORIZONTAL;
  3030.        EmitterX = 0;
  3031.        EmitterY = -50;
  3032.        EmitterWidth = 840;
  3033.        EmitterHeight = 480;
  3034.        AnimationID = "anim/particle/snow.pcx";
  3035.        BirthRate = 3;
  3036.        BirthRateVariation = 0;
  3037.        VelMX = 2000;
  3038.        VelMXVariation = 1000;
  3039.        VelMY = 10000;
  3040.        VelMYVariation = 1000;
  3041.        Life = 60;
  3042.        LifeVariation = 0;
  3043.        LeadTime = 50;
  3044.      }
  3045.    }
  3046.    
  3047.  
  3048.    
  3049.    
  3050.    /*  END OF ELEMENTS */
  3051.  };
  3052. }
  3053.  
  3054.